Separate lines from text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Separate lines from text file
# 1  
Old 01-26-2010
Separate lines from text file

I have a text file with lot of rows like..
Action & Adventure|2012: Supernova NR|2009-11-01 00:01:00|2010-05-01 23:59:00|Active|3
Action & Adventure|50 Dead Men Walking|2010-01-05 00:01:00|2010-06-30 23:59:00|Active|3
Action & Adventure|Afterwards|2009-11-26 00:01:00|2010-03-26 23:59:00|Deactivated|3

the 5th column can have different statuses.i want to extract all the rows from the file having only "Active" in the 5th column.
pls.help.

Thanks in advance.
# 2  
Old 01-26-2010
Code:
awk -F '|' '$5 ~ /^Active$/ {print $0}' filename

May be I should do some explaining too Smilie

awk is a unix filter.
-F : field separator, in your case its the character '|'
the awk script says that if the $5 (5th field) ~ (matches) the pattern /^Active$/ (^ and $ mean begins with and ends with respectively), then print $0, i.e the entire line.

Lemme know if that helped.

Last edited by linuxpenguin; 01-26-2010 at 02:06 PM.. Reason: explaining the code
# 3  
Old 01-26-2010
Thanks for the reply.

i tried like this but a.txt is empty
Code:
 
awk -F"|" '$5 ~ /^Active$/ {print $0}' FinalVHO.txt>a.txt

is there anything wrong with it?

Last edited by Scott; 01-26-2010 at 02:24 PM.. Reason: Added code tags
# 4  
Old 02-02-2010
well i copied the text from your post verbatim and ran the same line of code I provided and it worked. How big is your input file? Are there spaces/tabs around the word Active in the 5th column? Is there atleast one line in the file that has Active in the 5th column?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Help to join separate lines in a single one from xml file

Hi all, I need help to parse this xml file that has paragraphs broken in different lines and I would like to join in a single line. I hope you can understand my explanation. Thanks for any help/direction. The script could be in bash, awk, ruby, perl whatever please In the output I want:... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

3. UNIX for Beginners Questions & Answers

Ls to text file on separate lines

hi, I'm trying to print out the contents of a folder into a .txt file. The code I'm trying amongst variations is: ls -1 > filenames.txt but it prints them all on the same line ie. image102.bmpimage103.bmpimage104.bmpimage105.bmpimage106.bmp how can I change this? Please... (2 Replies)
Discussion started by: newbie100
2 Replies

4. Shell Programming and Scripting

Separate Text File into Two Lists Using Python

Hello, I have a pretty simple question, but I am new to Python and am trying to write a simple program. Put simply, I want to take a text file that looks like this: 11111 22222 33333 44444 55555 66666 77777 88888 and produce two lists, one containing the contents of the left column, one the... (0 Replies)
Discussion started by: Tyler_92
0 Replies

5. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (1 Reply)
Discussion started by: erlanq
1 Replies

6. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (2 Replies)
Discussion started by: erlanq
2 Replies

7. Shell Programming and Scripting

Combine the lines from separate text files

Hi All, I have three separate text files which has only one line and i want to combine these lines in one text file which will have three lines. cat file1.txt abc cat file2.txt 1265 6589 1367 cat file3.txt 0.98 0.36 0.5 So, I want to see these three lines in the... (9 Replies)
Discussion started by: senayasma
9 Replies

8. Shell Programming and Scripting

Read file contents and separate the lines when completes with =

Hi, I have a file like this cpsSystemNotifyTrap='2010/12/14 11:05:31 CST' Manufacturer=IBM ReportingMTMS=n/a ProbNm=26 LparName=n/a FailingEnclosureMTMS=7946-IQL*99G4874 SRC=B3031107 EventText=Problem reported by customer. CallHome=true Calendar I want to have a output like this... (6 Replies)
Discussion started by: dbashyam
6 Replies

9. Shell Programming and Scripting

Splitting text file into 2 separate files ??

Hi All, I am new to this forumn as well to the UNIX, I have basic knowledge of UNIX which I studied some years ago, now I have to do some shell scripting to load data into Oracle database using sqlldr utility, whcih I am able to do. I have a requirement where I need to do following operation. I... (10 Replies)
Discussion started by: shekharjchandra
10 Replies

10. Shell Programming and Scripting

script to separate bilingual text file

Hi all I have a bilingual text file, one language is English and another one is Assamese. I want to write English language text into one file and Assamese language text into another file. For Example- input file is as dsad জন gdfkghdfkghkdf hksdjhfkjsdfhk hksjdhfksdjf আনজনৰ মনত ghgj jkj... (11 Replies)
Discussion started by: wildhorse
11 Replies
Login or Register to Ask a Question