New answers tagged

3

You could simplify the whole thing if you use the // format for gsub: $ echo "ABC(T)" | awk '{gsub(/ABC\(T\)/,"ABC/G")}; print $0' ABC/G Then, you could simplify further by using print with no arguments (which is the same as print $0) or the 1 shorthand for printing (the default awk action for expressions that evaluate to true, such as 1; is to print the ...


1

You were very close. You just needed two \. That is because one of set is for the text itself passing through BASH, and the other would be the actual \ which is being parsed by awk. This seems to work for me: echo 'ABC(T)' | awk ' {gsub("ABC\\(T\\)","ABC/G")}; Print $0' "$FILENAME" And gives: ABC/G


1

Your last example is correct (assuming you use a shell like bash or ksh93 that understands [[ ... ]], but it seems that you do): if [[ "$ipvsrc" == "$ipvdst" ]]; then echo "Value OK"; fi The two variables that you compare contains strings, so quoting them and using == is correct. The reason you're getting no output is probably simply because the ...


0

Use the string manipulation constructs of parameter expansion. filename="${NotificationFile#????}" filename="${filename%.csv*}.csv" The first line sets filename to the value of NotificationFile with the first four characters stripped off. The second line removes everything from filename starting with .csv, and re-adds .csv to compensate.


0

If all the filenames end with .csv, and don't contain another .csv anywhere, use eg. sed to remove everything after that: Extract=$(echo $NotificationFile | sed 's/\.csv.*/.csv/') Combining that with what you had before: Extract=$(echo $NotificationFile | sed 's/\.csv_.*/.csv/' | cut -d "_" -f5-) The range N- means "to end of line", ie. not stopping at ...


0

For what you want, you could use sed. This is how I would do it. sed -ne 's/.*\(NB.*\)\_.*$/\FILENAME = \1 /p'


0

Perl has access to exported shell variables through the %ENV hash. It would probably be much simpler to use that. Something like: $ export repo arch linesToWrite $ perl -0pE 'use strict; my $repo = $ENV{"repo"}; my $arch = $ENV{"arch"}; s|\rsync:\/\/[^\]]+|$ENV{"linesToWrite"}|' I don't understand what you're trying to do with that ...


1

Assuming you just want the shell variables $repo $arch and $linesToWrite expanded, put them in double quotes and the rest in single quotes. Quoted strings next to each other make a single string ("a"'b' is ab). (I don't know what you are doing with the backslashes in the substitute command, so I left them, but you probably don't want them). perl -0pE 'use ...


2

Assuming the blank line in your example was for illustrative purposes only: sed -e '1~2{h;d};G;s/\n//' That sed expression in detail: 1~2 { # lines 1,3,5,7 etc. h # save line in the hold space d # delete (don't print yet) and start next line } # only reached on lines 2,4,6,8 etc. G # retrieve from hold space, append to current line ...


0

I assume the backslash before the > is just a typo. You can use this bash script if your text file is well formed: #!/bin/bash while read -r a && # store one line to $a read -r && # consume the blank line read -r b # store another line to $b do echo $b$a # join those two lines read -r # whatever, try ...


0

Based on your input, here is the output using the paste command to standard out: $ paste File1 File2 136667ED ap1_01_a_ap1_01_rails_07 136667ED -1294.6945,-2376.0317,21.8279 035B337C ap1_01_a_arrows_005 035B337C -1314.6719,-2721.7378,12.9467 79546F82 ap1_01_a_centreline_010 79546F82 -1283.1066,-2529.9771,12.9635 Since you have large files, you may ...


0

I used a variable named string to store your example. The below sed should split your string into lines, and separate fields with :. You can pipe it into a head -1 to get the first line : echo $string | sed 's/'"$#@&\*"'/\n/g'| sed 's/'"$&\*#@"'/:/g' Then you can use cut to get the first three fields from each line and verify whether they are ...


3

They don't match because FILTERED_CXXFLAGS has commas and ${TEMP_ARRAY[@]} does not: Flag: -DNDEBUG Filtered: -DDEBUG, Filtered: -DNDEBUG, If the commas are supposed to be there, then replace: if [ "$flag" = "$filtered" ]; then with: if [ "$flag" = "${filtered%%,}" ]; then Alternatively, if the commas are not supposed to be there, then the issue is ...


1

To ignore some lines on a line-by-line basis, add /unwanted pattern/ {next} or ! /wanted pattern/ {next} at the beginning of the script. Alternatively, filter with grep: grep -v 'unwanted pattern' | awk … or grep 'wanted pattern' | awk …. This may be faster if grep eliminates a lot of lines, because grep is typically faster than awk for the same task (grep ...


0



Top 50 recent answers are included