I'm using Linux and bash shell. I have a file (F1.txt) with contents like
Now, I would like to get the output as
It can be easily using "awk" as
Due to a complex requirement, I would like to do it only in a FOR loop as given below. I do quite a lot of business processing inside a FOR loop,
which gets extended more and more. It will be boring, if I start mentioning all the details, in-depth.
I know "awk" is quite powerful, but how to do Field Editing without awk, using the example given below.
Thanks a lot.
Moderator's Comments:
Please use code tags!
for your code and data!
Last edited by vbe; 03-16-2012 at 05:15 PM..
Reason: code tags
Using a 'for' loop to do this is a useless use of cat and useless use of backticks, precisely because of the reason you've discovered, among others -- it splits where it pleases, not on lines.
The shell's read builtin is much better suited. It can even split for you.
You have found the right method for using delimiters with read. You can handle it a little more gracefully by doing
while IFS="," read ... so you don't need to permanently change the value of IFS, but that's just a minor improvement, it does fundamentally the same thing.
i have a 2 fields in my DB
ID25333,1429291340lNormPUC-AP_MEX_UFM-GOL_44;PUC-AP_VEX_UFM-ROL_55;PUCAP_MEX_UFM-DOJ_49;
ID55555,1429291340lNormPUC-AP_PPP_UFM-HOL_44;PUC-AF_GEX_UJM-SOL_45;PUCAP_MEX_UFM-DOJ_59;and i need separate like this
ID25333,PUC-AP_MEX_UFM-GOL_44; ... (5 Replies)
Hi Experts,
I have a string with colon delimited, want 2nd colon to be changed to a pipe.
data:
101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3:
I am trying with sed, but can change only 1 occurance:
echo "101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3:" | sed 's/:/|/2'... (5 Replies)
Dear Experts,
How to use field separator in awk , when the field separation is needed as "||"
Example: (file1 )
aa || bb || cc || 1234
xx || yy || zz || 1123
Q:
If I want to print $3 and $4 only , with using the field separator "||"
How to write awk code: (6 Replies)
logs:
"/home/abc/public_html/index.php"
"/home/abc/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
how to use "cut" or "awk" or "sed" to get the following result:
abc
abc
xyz
xyz
xyz (8 Replies)
Is there any way to get the escaped version of a field in awk? For those that don't understand the question, here is a clarifying example. Lets say a field $1 gives me the string "(dumb'" (I've changed the delimiter to be something other than whitespace). If i use that value in a command in awk... (2 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
I guess it was getting a little messy on the other post so here goes:
Link to previous post for Question:
https://www.unix.com/shell-programming-scripting/111338-awk-replace-particular-field.html
Continuation of Question
hey i was messing around a bit ... made me wonder...
If the... (1 Reply)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)