awk help about show all the line beside the changed line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk help about show all the line beside the changed line
# 1  
Old 08-29-2012
awk help about show all the line beside the changed line

Code:
awk '/abc/{print $2}'

This will show the line contains abc and only show the "two filed"

But I want to the line contains "abc" will only show $2, other line still show.

and I want to know awk's way about not only show the line besides changed line

Thanks
# 2  
Old 08-29-2012
if you show a sample file, a desired output and you're getting now, we might be able to help - reading the current 'explanation' is somewhat confusing....
This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 08-29-2012
Code:
awk '{if ($0 ~ /abc/) print $2 ; else print}'

This User Gave Thanks to delugeag For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Grep: show only first match per line?

Hi, can I make grep stop after finding the first occurrence of a regex in a line? Given: file with various regex patterns file to be grep'ed Sadly some of the regex patterns cannot be limited any further, so grep -Eiof patterns.txt file.txt (GNU grep 2.20) will give me possibly n hits... (4 Replies)
Discussion started by: stresing
4 Replies

3. Shell Programming and Scripting

Using sed to show even numbers and the line

Hello, I have an assignment that requires us to use sed only. The first part of the assignment says to use a sed script to print only the even lines, but if it is print, the number of that lines needs to be printed before the text. ex: 2 line 2 text 4 line 4 text 6 line 6 text ... (3 Replies)
Discussion started by: stevent518
3 Replies

4. Shell Programming and Scripting

print - for printing whole line, but delimeters are changed to spaces

Hi consider the source file R|field1|field2 using the print statement in awk prints it as R field1 field2 Is there an easier way to print the whole line in its original format (i.e. with | delimiters) than doing print $1"|"$2"|"$3 ?? Thanks Storms (1 Reply)
Discussion started by: Storms
1 Replies

5. Shell Programming and Scripting

will only show every 3rd line

Hi, how will i show every 3rd line of the file. Ex. line 1 line 2 line 3 line 4 line 5 line 6 line 7 Output: line 2 line 5 line 6 tyhanks ---------- Post updated at 03:39 AM ---------- Previous update was at 03:37 AM ---------- (2 Replies)
Discussion started by: kenshinhimura
2 Replies

6. UNIX for Dummies Questions & Answers

Show the entire line using ps

Using the vanilla ps -ef I noticed that the CMD (or command) line gets cut off after 90 characters UID PID PPID C STIME TTY TIME CMD root 6020 3822 0 Jun 19 ? 0:01 ./webservd-wdog -r /export/opt/sows/61sp4 -d /export/opt/sows/61sp4/https-logse Googling... (4 Replies)
Discussion started by: SixSigma1978
4 Replies

7. Shell Programming and Scripting

sed - print old line and new changed line

hello, i have a file "TEST" and want to change the digit(s) after "=" . but i also want to print the old entry with a comment (for information). i want to use "sed", is it possible ? file: TEST = 10 # comment default value: 0 sed , with "p" , i can print the old entry, but i want to... (2 Replies)
Discussion started by: bora99
2 Replies

8. UNIX for Dummies Questions & Answers

how to show it on separate line

# echo $PATH /home/user01/bin:/usr/local/bin:/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/dist/perl5/bin:/dist/fsf/bin:.:/usr/dt/bin:/etc/dt/tbin:/usr/openwin/bin how to show the PATH in separate line, ie: /home/user01/bin /usr/local/bin /usr/bin:/bin /usr/ccs/bin /usr/ucb etc...... (2 Replies)
Discussion started by: userking
2 Replies

9. Shell Programming and Scripting

How to print empty line when the a field is changed

Hi all, I have this input file .. BSS01 107 Swafieh 11/06/2008 12:06:57 BSS01 111 Ramada_Hotel 12/06/2008 11:37:20 BSS01 147 Kalha_Rep 11/06/2008 19:13:39 BSS01 147 Kalha_Rep ... (9 Replies)
Discussion started by: yahyaaa
9 Replies

10. UNIX for Dummies Questions & Answers

Email to show only summary line

Hi everyone, can you suggest a way fro me to set something up so that i can start mail or mailx and have only the summary line of each email displayed, 24 lines (emails) per page and keep on navigating down throught the summary lines a full page at a time? My users have hundreds of emails ....... (0 Replies)
Discussion started by: gio001
0 Replies
Login or Register to Ask a Question