Yes, sorry about the missing quotes around $line. I posted the suggestion "on the run" and didn't have time to try it out.
Here is a quick explanation of what is happening.
$0 = Current input line
substr(string, start, len) extract a substring starting at character position start for a length of len if len is not supplied it goes to end of string.
substr($0,23,4)+0==F
This get chars 23-26 of the input line
Adds zero (this converts the value to an integer which is needed as " 21" <> 21)
Compare this value with variable F if it's a match the code in {} is processed
{$0=substr($0,1,22) sprintf("%4d",T) substr($0,27)}
This rebuilds the input line with chars 1-22 + T (padded to 4 chars wide) + chars 27-end
1
This value is not zero in awk that is a true (not false) expression so the code in {} that follows is executed. In this case no code follows so the default action is performed which is "print the input line". Note that we may have changed the input line in the statement above (or we might not have all depending on the contents of T chars 23-26 of the input line)
This could also be expanded to:
Because your using bash you could also use bash substrings (remember index starts at zero not 1), this solution will be much faster as it doesn't need to load and execute awk for each line processed:
Last edited by Chubler_XL; 02-14-2013 at 05:31 PM..
Hello,
I'm trying the solve the following problem.
I have a file which I intend to use as a csv called master.csv
The columns are separated by commas.
I want to change the text on a specific row in either column 3,4,5 or 6 from xxx to yyy depending upon if column 1 matches a specified pattern.... (3 Replies)
Hi,
I have gigabytes of text files that I need to search for "&" and replace with "&". Is there a way to do this efficiently (like sed command)?
Hope you could help.
Thanks. (17 Replies)
Hello, I am using awk to match text in a tab separated field and am able to do so when matching the exact word. My problem is that I would like to match any sequence of text in the tab-separated field without having to match it all. Any help will be appreciated. Please see the code below.
awk... (3 Replies)
Hi There...
I need to serach and replace a strings in a text file.
My file has; books.amazon='Let me read' and the output needed is
books.amazon=NONFOUND
pls if anybody know this can be done in script sed or awk.. i have a list of different strings to be repced by NONFOUND.... (7 Replies)
how to replace the 3rd colum? Each line begins similarly, but they all ends variously.
XX YY 03 variable text here
XX YY 03 more variable text here
XX YY 03 even more variable text here really long setence
XX YY 03 variable numbers also appear 03 11. 123 456
XX YY 03 the occasional comma,... (4 Replies)
hello all
greeting for the day
i have a text file as the following
text.xml
abcd<FIELD>123.456</FIELD>efgh
i need to replace the value between <FIELD> and </FIELD> by using awk command.
please throw some light on this.
thank you very very much
Erik (5 Replies)
Hi all,
I have a requirement where i have to search data between strings 'SELECT' and ';' and replace this text as "SELECT.....;" so that i can export this extracted string into a excel cell.
Please suggest on this. (5 Replies)
I have a text file with following content (3 lines)
filename : output.txt
first line:12/12/2008
second line:12/12/2008
third line:Y
I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before.
I tried using cat output.txt... (4 Replies)
script is as below
v_process_run=5
typeset -i p_cnt=0
pdata=/home/proc_data.log
while
do
# execute script in background
dummy_test.sh "a1" "a2" &
p_cnt=$p_cnt+1
echo "data : $p_cnt : Y" >> $pdata
done
file created with following data in... (1 Reply)
Hi, I am trying something like this: Let's say I have a file called File1 with contents:
x=-0.3
y=2.1
z=9.0
I have another file, File2, with contents:
xx=
yy=
zz=
(nothing after "="). What I want to do is get the value of x in File1 and set it to xx in File2, i.e., xx=-0.3. And the... (3 Replies)