![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl: Search for string on line then search and replace text | Crypto | Shell Programming and Scripting | 4 | 01-04-2008 07:24 AM |
| Howto capture data from rs232port andpull data into oracle database-9i automatically | boss | UNIX for Dummies Questions & Answers | 1 | 09-22-2007 11:35 PM |
| search and grab data from a huge file | ting123 | UNIX for Dummies Questions & Answers | 1 | 06-06-2006 06:41 PM |
| search and replace dynamic data in a shell script | csejl | Shell Programming and Scripting | 8 | 10-21-2003 07:33 PM |
| Advanced Search Problems.. Search by User Name | Neo | Post Here to Contact Site Administrators and Moderators | 1 | 05-18-2003 09:28 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#8
|
|||
|
|||
|
So the question is, how do I print the first field from the first and second lines of a file?
Code:
awk '(NR == 1 || NR == 2) { print $1 }' /etc/hosts
|
| Forum Sponsor | ||
|
|
|
#9
|
||||
|
||||
|
Quote:
Code:
awk 'NR<3{print $1}' /etc/hosts
|
|
#10
|
|||
|
|||
|
hoping near equal.
still i didnt get the exact output i want. $hostname datas $for i in `hostname` do grep $i /etc/hosts |awk '(NR == 1 || NR == 2) { print $1,$2 }' > output tail -1 output ifconfig lan1 $i done this is the sample script. So what i want to change my current lan config to backup lan config. datas is my curerent data1 is my backup, how iwll i do that? |
|
#11
|
|||
|
|||
|
Drop the grep. And the for loop. If you just want the second line then say so.
Code:
ifconfig lan1 `awk 'NR==2 { print $1 }' /etc/hosts`
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| linux, regex, regular expressions, ubuntu |
| Thread Tools | |
| Display Modes | |
|
|