Hi I need a bash script that can search through a text file and when it finds 'FSS1206' I need to put a Letter F 100 spaces after the second instance of FSS1206
The format is the same throughout the file I need to repeat this on every time it finds the second 'FSS1206' in the file
I have really not explained this very well but see example below, I need an F at that position. :wall:
or would it be easier to search for "71502FSS1206 FSS1206" and put a F 100 spaces after this rather than just search for a single instance of FSS1206?
71502FSS1206 FSS1206 000000000000200100000000000820009958170009958181200100005952
71502FSS1206 FSS1206 000000000000200100000000000820009958170009958181200100005952 F
From the description I am not sure, if you mean a 2nd occurence in the same line or another line.
If it is meant per line, something like this might work:
$> cat infile
aa FSS1206 vv
bb something
aa FSS1206 vv
aa FSS1206 vv
completeley different
aa FSS1206 vv
it seems
aa FSS1206 vv
$ awk 'f && /FSS1206/ {print NR,$0,"F"; f=0; next} /FSS1206/ {f=1}' infile
3 aa FSS1206 vv F
6 aa FSS1206 vv F
The example input file is shorter so you can adjust the output of "F" with printf
for example. I added NR to print the line number.
It will recognize every 2nd line that matches the pattern.
If it is meant per line, you can try this:
$ cat infile
aa FSS1206 vv iquwegh2pg3FSS6uagwf777
aa FSS1206 vv iquwegh2pg3FSS1206uagwf777
aa FSS1206 vv iquwegh2pg3FSS1206uagwf777FSS1206
$ awk -F"FSS1206" 'NF==3 {print $0, " F"; next} {print}' infile
aa FSS1206 vv iquwegh2pg3FSS1206uagwf777
You can exeriment with printf
for the "F" here too.
Try:
awk '$2=="FSS1206"{$0=$0" F"}1' infile > outfile
sorry for not explaining better, there are multiple instances FSS1206.
Would it be easier searching for
71502FSS1206 FSS1206
and place a letter F 100 spaces after every occurrence found within the file
Is this possible?
This didn't appear to do anything.
Thanks for all the help its appreciated.