tag:blogger.com,1999:blog-1255024703457423340.post4730820296971544908..comments2024-03-13T13:54:48.044+05:30Comments on The UNIX School: awk - Read a file and split the contentsGuru Prasadhttp://www.blogger.com/profile/07898245472802947101noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-1255024703457423340.post-10392460258790747582019-08-28T20:38:19.645+05:302019-08-28T20:38:19.645+05:30Very good.
I'd just say that " The condi...Very good. <br />I'd just say that " The conditon 'NR!=1' indicates not to execute the action part for the first line of the file,"<br />is true, but really what it's doing is executing a test; if the line number != 1, then the test returns true, and what follows the test is executed. So in reality what it's doing is printing the line as long as it's not line number 1, rather than not printing line number 1. Anonymoushttps://www.blogger.com/profile/14724872859089548630noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-48824382343000888782019-04-16T16:59:26.712+05:302019-04-16T16:59:26.712+05:30Hi All,
I have data like this
a,b,c,d,e
h,i,j,k...Hi All,<br /><br />I have data like this <br /><br />a,b,c,d,e<br />h,i,j,k,l<br />m,o,p,b,y<br /><br />i wish to double quote each column and from 3rd column to till end it should appear as one column<br /><br />"a","b","c,d,e"<br />"h","i","j,k,l<br />"m","o","p,b"<br /><br />How to do it.Anonymoushttps://www.blogger.com/profile/17456470998668335171noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-66351182459464809692019-03-30T18:40:03.165+05:302019-03-30T18:40:03.165+05:30I'm getting an issue where the output file has...I'm getting an issue where the output file has only one line from the whole input file primtep and that too ending with a colonAnonymoushttps://www.blogger.com/profile/10844148335664558013noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-47920777688237388512016-12-19T10:18:55.264+05:302016-12-19T10:18:55.264+05:30Thank you very much for the detailed examples with...Thank you very much for the detailed examples with explanations.<br /> Anonymoushttps://www.blogger.com/profile/02781584585848015494noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-4551185101543999582016-04-16T19:28:49.503+05:302016-04-16T19:28:49.503+05:30Hi,
Is 7th and 9th examples are correct ??Hi,<br /><br />Is 7th and 9th examples are correct ??Anonymoushttps://www.blogger.com/profile/07016655821759020573noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-14761124222976164502016-04-07T16:14:21.827+05:302016-04-07T16:14:21.827+05:30Hi,
Please anyone solve my issue.
I have a file ...Hi,<br /><br />Please anyone solve my issue.<br /><br />I have a file with multiple lines. I want to create a file from input file which contains lines starting from Begin to Line starting from End.<br /><br />Example:<br /><br />Begin:123 Its is = 01c<br />St:13e is =44c<br /><br />End:234 sd=5C<br /><br />Begin :sfvf= 7C<br />str:98 +c<br /><br />End:hs =7C<br /><br /><br />now if i consider above as input file, I want 2 files as out which spilts above file from Begin to End<br />Anonymoushttps://www.blogger.com/profile/18061383822721909072noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-21349071596043784352016-02-05T00:27:31.048+05:302016-02-05T00:27:31.048+05:30awk -F[=,] '{for(i=2;i<=NF;i++)print $i}...awk -F[=,] '{for(i=2;i<=NF;i++)print $i}' file.txt > file1.txtAnonymoushttps://www.blogger.com/profile/13506580145254877210noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-3531430453487956252016-01-06T22:49:34.882+05:302016-01-06T22:49:34.882+05:30awk -F[=,] '{for(i=2;i<=NF;i++)print $i}...awk -F[=,] '{for(i=2;i<=NF;i++)print $i}' file.txtGuru Prasadhttps://www.blogger.com/profile/07898245472802947101noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-28951414074935581992016-01-06T11:36:23.212+05:302016-01-06T11:36:23.212+05:30I have a file containing following format:-
file....I have a file containing following format:-<br /><br />file.text:-<br />userread=ruser1,rusers2,ruser3<br />userwrite=wuser1,wuser2,wuser3<br /><br />I need to list all users only in a different file.<br />can you please tell me to extract usernames from this file.txt.Prabhahttps://www.blogger.com/profile/04226013161208421877noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-37879463675398285892015-12-12T01:47:26.576+05:302015-12-12T01:47:26.576+05:30thank you for this good explanation
thank you for this good explanation<br />Anonymoushttps://www.blogger.com/profile/07614199510543802913noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-77581402457945525532015-10-29T22:45:12.448+05:302015-10-29T22:45:12.448+05:30Can you please elaborate more ?Can you please elaborate more ?Guru Prasadhttps://www.blogger.com/profile/07898245472802947101noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-20260022260286782572015-10-27T10:15:17.279+05:302015-10-27T10:15:17.279+05:30i/p:
Line1
Line2
Line3
Line4
Line5
o/p:
Line1
Line...i/p:<br />Line1<br />Line2<br />Line3<br />Line4<br />Line5<br />o/p:<br />Line1<br />Line2<br />Line3<br />Line4<br />Line5<br />I have an input as mentioned above. Line1,2,3 etc is a whole line of different words e.g create table tablename ...... The 2nd scenario is also valid where multiple lines will be between two start and end tags. Is there a way to extract this using awk ?<br /><br />--SamirAnonymoushttps://www.blogger.com/profile/02256109109872679001noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-80404623340444277882015-09-10T17:55:37.680+05:302015-09-10T17:55:37.680+05:30You have to define a variable at awk,
awk -v ind=&...You have to define a variable at awk,<br />awk -v ind="${index}" -F',' '{print $ind}' your_file<br />will print 1st field if index=1 :)Anonymoushttps://www.blogger.com/profile/04843812904331964461noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-49305371519423258952015-03-06T22:31:24.567+05:302015-03-06T22:31:24.567+05:30AwesomeAwesomeSathish Subramaniamhttps://www.blogger.com/profile/10831982750927506344noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-90184893055720215912014-10-02T17:26:49.385+05:302014-10-02T17:26:49.385+05:30The intention was to print the first column using ...The intention was to print the first column using the 'index' variable.<br />print index -> 1<br />print $index -> value of 1st columnGuru Prasadhttps://www.blogger.com/profile/07898245472802947101noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-54432063327411324442014-09-28T22:32:39.120+05:302014-09-28T22:32:39.120+05:30Hi Guru,
If we just make use of $index instead of ...Hi Guru,<br />If we just make use of $index instead of $$index.Then the statement will look something like below:<br />awk '{print 1}' file<br />which will print 1 number of times equal to number of lines in 'file'.<br />Can you please explain how $index will suffice the requirementAnonymoushttps://www.blogger.com/profile/15313343337313573194noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-85234261765640239022014-08-15T21:23:10.955+05:302014-08-15T21:23:10.955+05:30Just $index should be fine.Just $index should be fine.Guru Prasadhttps://www.blogger.com/profile/07898245472802947101noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-32162894482197518832014-07-26T21:45:47.572+05:302014-07-26T21:45:47.572+05:30Wow awk is so cool! Thanks for the article, it'...Wow awk is so cool! Thanks for the article, it's useful and really easy to understand.Andre Silveirahttps://www.blogger.com/profile/12967222623475638490noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-52334449364005836002014-07-17T01:53:53.257+05:302014-07-17T01:53:53.257+05:30can you do the following:
awk '{print $$index}...can you do the following:<br />awk '{print $$index}' file<br />where index is a variable that holds a number?<br />so if index =1, it would be the same as:<br />awk '{print $1}' fileAnonymoushttps://www.blogger.com/profile/01185976816996461314noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-39780440315278592202014-04-24T17:32:40.028+05:302014-04-24T17:32:40.028+05:30Good Post !! very helpfulGood Post !! very helpfulAmrut & Deepalihttps://www.blogger.com/profile/15164391469081442314noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-10035657766217281242014-04-24T14:08:27.063+05:302014-04-24T14:08:27.063+05:30Hi! Thanks for these usefull little tips my friend...Hi! Thanks for these usefull little tips my friend :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-28527955542244575392013-10-02T23:19:52.658+05:302013-10-02T23:19:52.658+05:30Thanks I used this to extract the 2nd column in my...Thanks I used this to extract the 2nd column in my CSV comma separate file myfile.txt<br />-------<br />myfile.txt<br /><br />Country,City,AccentCity,Region,Population,Latitude,Longitude<br />ad,aixas,Aixàs,06,,42.4833333,1.4666667<br />ad,aixirivali,Aixirivali,06,,42.4666667,1.5<br />ad,aixirivall,Aixirivall,06,,42.4666667,1.5<br /><br />-------<br />awk -F"," 'NR!=1{print $2}' myfile.txtLindylexhttps://www.blogger.com/profile/11290552410818220591noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-45481142496873099142013-10-02T23:17:00.300+05:302013-10-02T23:17:00.300+05:30Two hours later and this saved my life extracting ...Two hours later and this saved my life extracting the second column of this comma separated file (CSV) myfile.txt<br /><br />Country,City,AccentCity,Region,Population,Latitude,Longitude<br />ad,aixas,Aixàs,06,,42.4833333,1.4666667<br />ad,aixirivali,Aixirivali,06,,42.4666667,1.5<br />ad,aixirivall,Aixirivall,06,,42.4666667,1.5<br /><br />awk -F"," 'NR!=1{print $2}' myfile.txt<br /><br />Thanks, Lindylex<br />Lindylexhttps://www.blogger.com/profile/11290552410818220591noreply@blogger.comtag:blogger.com,1999:blog-1255024703457423340.post-23856948663026802922013-08-28T10:19:36.739+05:302013-08-28T10:19:36.739+05:30Thanks..it was usefullThanks..it was usefullAGNRhttps://www.blogger.com/profile/10408973130652592482noreply@blogger.com