![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| print line whatever line i want in a file... there any way | kittusri9 | Shell Programming and Scripting | 1 | 05-15-2008 09:37 AM |
| awk print the next line on the current line | ajp7701 | Shell Programming and Scripting | 4 | 04-17-2008 01:50 PM |
| How to print 3rd to last line of file? | NivekRaz | Shell Programming and Scripting | 2 | 09-10-2007 05:04 PM |
| Print file line by line | handak9 | Shell Programming and Scripting | 2 | 10-20-2005 05:44 AM |
| cannot print 3 variables on same line | Chris Jones | Shell Programming and Scripting | 2 | 04-20-2004 06:31 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi All,
I know that i can print the lines from awk just using the print method, but i need to print stuff before it i.e: BEGIN { i=0 } { i++ print i ")" } END { } Here the output is: 1) Line 2) Line 3) etc But i need it to be on the same line, i.e. 1) Line 2) Line Thanks, Chris. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
print i ")" $0 |
|
#3
|
|||
|
|||
|
Thanks vgersh99, knew it would be something simple. And ill take a look at printf.
Thanks again, Chris. |
|
#4
|
|||
|
|||
|
Actually i have another problem, i didnt actually want to print the line to out put i wanted to save it as an array and print at the end i.e.
BEGIN { i=0 } { i++ Lines[i]= i ")" $0 } END { for(Line in Lines) { print Lines[Line] } } Problem here is that the array is returned totally unordered and i get an output like: 4) blah 2) blah 17) blah Whats happening? |
|
#5
|
|||
|
|||
|
nevermind just did
for(j=0;J<i;j++) { print Lines[j] } Ta Chris. |
|
#6
|
|||
|
|||
|
lol, im back :-). I have no problems printing the results to the screen but i can seem to add them to a file i.e.
for(j=1;J<=i;j++) { print Lines[j] > Out } Gives me this error: awk: cmd. line:17: (FILENAME=- FNR=28) fatal: expression for `>' redirection has null string value ive tryed this but still doesnt work: for(j=1;J<=i;j++) { if(Lines[j]!=null) { print Lines[j] > Out } } |
|
#7
|
||||
|
||||
|
Code:
for(j=1;J<=i;j++) print Lines[j] > "Out" |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|