Extracting data from file-shell scripting--please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting data from file-shell scripting--please help
# 1  
Old 11-04-2011
Extracting data from file-shell scripting--please help

hello friends,

my file is like
Code:
123	|asd|asd|asd
123_1|awd|asw|asw
121	|wer|qwe|wee
124	|weq|qwe|iop
1_23	|bla|blh|bha
145	|ghj|jkl|ghj
146	|qwe|qwe|wer
154	|asd|wer|qw_e
134_5|qwe|wer|qw_e

is their any solution to retrive only those lines which are having only 3 numerical letters in first coloumn
it means the output should be like
Code:
123	|asd|asd|asd
121	|wer|qwe|wee
124	|weq|qwe|iop
145	|ghj|jkl|ghj
146	|qwe|qwe|wer
154	|asd|wer|qw_e

i hope you understood my problem
please let me know if you need any more infomation to solve this
Thanks in advance.
pankaj

Last edited by Scott; 11-04-2011 at 05:25 AM.. Reason: Code tags
# 2  
Old 11-04-2011
Code:
 
$ nawk -F\| '$1~/^[0-9][0-9][0-9] $/' input
123 |asd|asd|asd
121 |wer|qwe|wee
124 |weq|qwe|iop
145 |ghj|jkl|ghj
146 |qwe|qwe|wer
154 |asd|wer|qw_e

# 3  
Old 11-04-2011
Hi friend,
thanks for your quick reply!!!

what is input in the above command is it the name of the file which i am giving as input.
if my file name is in.txt then according to you command should be like
Code:
nawk -F\| '$1~/^[0-9][0-9][0-9] $/' in.txt

right???

Last edited by Scott; 11-04-2011 at 05:26 AM.. Reason: Please use code tags
# 4  
Old 11-04-2011
Another one...
Code:
sed -n "/^[0-9]\{3\} /p" input_file

--ahamed

---------- Post updated at 11:22 PM ---------- Previous update was at 11:21 PM ----------

Quote:
Originally Posted by PankajChawla
nawk -F\| '$1~/^[0-9][0-9][0-9] $/' in.txt

right???
Yes
# 5  
Old 11-04-2011
Hi Ahamed

Thanks

but you know i am not getting any output after running this command.

--Pankaj
# 6  
Old 11-04-2011
can you post your original contents (atleast few lines)

and make sure, you have a space after 3 numbers ( 123 |)
# 7  
Old 11-04-2011
Are you trying on the same file you have posted here? Both the solutions are not working?
Can you also post the output of od -bc input_file?
If there is \r in the output, do the following dos2unix input_fileand try again

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

How to extract data from XML file using shell scripting?

Hi , I have input file as XML. following are input data #complex.xml Code: <?xml version="1.0" encoding="UTF-8"?><TEST_doc xmlns="http://www.w3.org/2001/XMLSchema-instance"> <ENTRY uid="123456"> <protein> <name>PROT001</name> <organism>Human</organism> ... (1 Reply)
Discussion started by: arun_kohan
1 Replies

4. Shell Programming and Scripting

How to extract data from xml file using shell scripting?

Hi evry1, This is my 1st post in this forum.Pls help me I want to extract some data froma xml file which has 2000 lines using shell scripting. Actually my xml file has some "audio and video codes" which i need to arrange in a column wise format after extracting it using shell scripting.I... (4 Replies)
Discussion started by: arun_kohan
4 Replies

5. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

6. Shell Programming and Scripting

Shell scripting to extract data from file

Hi, i want to fetch the data from the alert log file, for a particular time interval. Example : Alert log content : Thu Mar 18 08:47:36 2010 Completed: alter database open Thu Mar 18 19:13:38 2010 MMNL absent for 6390 secs; Foregrounds taking over Fri Mar 19 08:30:52 2010... (1 Reply)
Discussion started by: Pinki018
1 Replies

7. UNIX for Dummies Questions & Answers

How to cut data block from .txt file in shell scripting

Hi All, Currently i have to write a script. For which i need to cut a block from .txt file. I know the specific word that starts the block and ends the block. Can we do it in shell scripting..? Please suggest.... (6 Replies)
Discussion started by: pank29
6 Replies

8. Shell Programming and Scripting

urgent-extracting block data from flat file using shell script

Hi, I want to extract block of data from flat file. the data will be like this start of log One two three end of log i want all data between start of log to end of log i.e One two three to be copied to another file. This particular block may appear multiple times in same file. I... (4 Replies)
Discussion started by: shirish_cd
4 Replies
Login or Register to Ask a Question