Redirecting lines containing specific value at second field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirecting lines containing specific value at second field
# 1  
Old 02-26-2014
Redirecting lines containing specific value at second field

How to find and redirect such line from a file to another using single composite command?

Code:
DPSDMX10   DPSDMX10_T DMX_DP     COMPLETED             01/31/2014 202626 01/31/2014 202630                           node SYS_BATCH                       9027   100 0064506 0404544 01/31/2014 user       000  000  00  0362074

here I want only those line to be redirected which has DMX substr in second field

Thank You

Last edited by Scrutinizer; 02-26-2014 at 05:40 AM.. Reason: code tags
# 2  
Old 02-26-2014
Can you post sample input? What have you tried?
# 3  
Old 02-26-2014
Code:
grep "str" input.txt > output.txt

# 4  
Old 02-26-2014
Code:
DPSDMX10   DPSDMX10_T DMX_DP     COMPLETED             01/31/2014 202626 01/31/2014 202630                           node SYS_BATCH                       9027   100 0064506 0404544 01/31/2014 user       000  000  00  0362074

here I want only those line to be redirected which has DMX substr in second field

---------- Post updated at 02:44 PM ---------- Previous update was at 02:41 PM ----------

Quote:
Originally Posted by SriniShoo
Code:
grep "str" input.txt > output.txt

this will also redirect lines which contain DMX in other fields
# 5  
Old 02-26-2014
Code:
awk '$2 ~ /DMX/' input.txt > output.txt

This User Gave Thanks to SriniShoo For This Post:
# 6  
Old 02-26-2014
Code:
awk ' $2 ~ /DMX/ ' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove lines in file if specific field matches

I am trying to remove lines in the target.txt file if $5 before the - in that file matches sorted_list. I have tried grep and awk. Thank you :). grep grep -v -F -f targets.bed sort_list grep -vFf sort_list targets awk awk -F, ' > FILENAME == ARGV {to_remove=1; next} > ! ($5 in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

awk repeat one field at all lines and modify field repetitions

Hello experts I have a file with paragraphs begining with a keeping date and ending with "END": 20120301 num num John num num A keepnum1 num num kathrin num num A keepnum1 num num kathrin num num B keepnum2 num num Pete num num A keepnum1 num num Jacob num... (2 Replies)
Discussion started by: phaethon
2 Replies

3. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

4. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

5. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

6. Shell Programming and Scripting

Combine multiple lines in file based on specific field

Hi, I have an issue to combine multiple lines of a file. I have records as below. Fields are delimited by TAB. Each lines are ending with a new line char (\n) Input -------- ABC 123456 abcde 987 890456 7890 xyz ght gtuv ABC 5tyin 1234 789 ghty kuio ABC ghty jind 1234 678 ght ... (8 Replies)
Discussion started by: ratheesh2011
8 Replies

7. Shell Programming and Scripting

Print Specific lines when found specific character

Hello all, I have thousand file input like this: file1: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ | | | |$$ $$ UERT | TTYH | TAFE | FRFG |$$ $$______|______|________|______|$$ $$ | | | |$$ $$ 1 | DISK | TR1311 | 1 |$$ $$ 1 |... (4 Replies)
Discussion started by: attila
4 Replies

8. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

9. UNIX for Dummies Questions & Answers

redirecting with lines number

Is there a command for this? (1 Reply)
Discussion started by: JamieMurry
1 Replies

10. Shell Programming and Scripting

Redirecting my output to a specific file

Hi guys am doing some checking inside my script and i want to redirect my output to a specific file for example checking if a move was successfully done and was writing on the screen whether the move was successful or not and now want to write same thing into a file... I am new to shell... (2 Replies)
Discussion started by: Lutchumaya
2 Replies
Login or Register to Ask a Question