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
# 8  
Old 11-04-2011
Code:
 
$ nawk '/^[0-9][0-9][0-9] /' in.txt
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

# 9  
Old 11-04-2011
Code:
> nawk -F\| '$1~/^[0-9][0-9][0-9] $/' new.txt
> cat new.txt
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
>

@ Ahamed i also tried your code and it resulted in same
NO OUTPUT

---------- Post updated at 12:19 PM ---------- Previous update was at 12:15 PM ----------
Code:
> od -bc new.txt
0000000 061 062 063 011 174 141 163 144 174 141 163 144 174 141 163 144
           1   2   3  \t   |   a   s   d   |   a   s   d   |   a   s   d
0000020 012 061 062 063 137 061 011 174 141 167 144 174 141 163 167 174
          \n   1   2   3   _   1  \t   |   a   w   d   |   a   s   w   |
0000040 141 163 167 012 061 062 061 011 174 167 145 162 174 161 167 145
           a   s   w  \n   1   2   1  \t   |   w   e   r   |   q   w   e
0000060 174 167 145 145 012 061 062 064 011 174 167 145 161 174 161 167
           |   w   e   e  \n   1   2   4  \t   |   w   e   q   |   q   w
0000100 145 174 151 157 160 012 061 137 062 063 011 174 142 154 141 174
           e   |   i   o   p  \n   1   _   2   3  \t   |   b   l   a   |
0000120 142 154 150 174 142 150 141 012 061 064 065 011 174 147 150 152
           b   l   h   |   b   h   a  \n   1   4   5  \t   |   g   h   j
0000140 174 152 153 154 174 147 150 152 012 061 064 066 011 174 161 167
           |   j   k   l   |   g   h   j  \n   1   4   6  \t   |   q   w
0000160 145 174 161 167 145 174 167 145 162 012 061 065 064 011 174 141
           e   |   q   w   e   |   w   e   r  \n   1   5   4  \t   |   a
0000200 163 144 174 167 145 162 174 161 167 137 145 012 061 063 064 137
           s   d   |   w   e   r   |   q   w   _   e  \n   1   3   4   _
0000220 065 011 174 161 167 145 174 167 145 162 174 161 167 137 145 012
           5  \t   |   q   w   e   |   w   e   r   |   q   w   _   e  \n
0000240


Last edited by Scott; 11-04-2011 at 05:26 AM.. Reason: Code tags
# 10  
Old 11-04-2011
Tab is present... Try this...
Code:
sed -n "/^[0-9]\{3\} */p" input_file

--ahamed
# 11  
Old 11-04-2011
hi ahamed
i am trying on the same file

output of od -bc
Code:
> od -bc new.txt
0000000 061 062 063 011 174 141 163 144 174 141 163 144 174 141 163 144
           1   2   3  \t   |   a   s   d   |   a   s   d   |   a   s   d
0000020 012 061 062 063 137 061 011 174 141 167 144 174 141 163 167 174
          \n   1   2   3   _   1  \t   |   a   w   d   |   a   s   w   |
0000040 141 163 167 012 061 062 061 011 174 167 145 162 174 161 167 145
           a   s   w  \n   1   2   1  \t   |   w   e   r   |   q   w   e
0000060 174 167 145 145 012 061 062 064 011 174 167 145 161 174 161 167
           |   w   e   e  \n   1   2   4  \t   |   w   e   q   |   q   w
0000100 145 174 151 157 160 012 061 137 062 063 011 174 142 154 141 174
           e   |   i   o   p  \n   1   _   2   3  \t   |   b   l   a   |
0000120 142 154 150 174 142 150 141 012 061 064 065 011 174 147 150 152
           b   l   h   |   b   h   a  \n   1   4   5  \t   |   g   h   j
0000140 174 152 153 154 174 147 150 152 012 061 064 066 011 174 161 167
           |   j   k   l   |   g   h   j  \n   1   4   6  \t   |   q   w
0000160 145 174 161 167 145 174 167 145 162 012 061 065 064 011 174 141
           e   |   q   w   e   |   w   e   r  \n   1   5   4  \t   |   a
0000200 163 144 174 167 145 162 174 161 167 137 145 012 061 063 064 137
           s   d   |   w   e   r   |   q   w   _   e  \n   1   3   4   _
0000220 065 011 174 161 167 145 174 167 145 162 174 161 167 137 145 012
           5  \t   |   q   w   e   |   w   e   r   |   q   w   _   e  \n
0000240


Last edited by Scott; 11-04-2011 at 05:27 AM.. Reason: Code tags
# 12  
Old 11-04-2011
The above code is not working?
Code:
sed -n "/^[0-9]\{3\}\t/p" input_file

sed -n "/^[0-9]\{3\}<TAB Key>/p" input_file
#you have to press the tab kez on your key board for the above command

--ahamed
# 13  
Old 11-04-2011
Orignal file--please

Hi Ahamed,

Below is the orignal file on which i am working,please


input file
Code:
 1_52 | EOB, TUE 10/11/11 | EOB, MON 10/17/11 | asded
 153 | EOB, WED 10/19/11 | EOB, FRI 10/21/11 | asded
 {color:#ff0000}\********\*{color} | {color:#ff0000}Code{color} | {color:#ff0000}Freeze{color} | {color:#ff0000}\********************\*{color}
 154 | EOB, WED 10/26/11 | EOB, THU 10/27/11 | Only
 154_3 \\ | NOON, THURS 11/3/11 \\ | N/A \\ | Planned 
 154_4 \\ | NOON, Fri 11/4/11 \\ | N/A \\ | Planned 
 155 | EOB, TUE 11/08/11 | EOB, TUE 11/15/11 | Guide
 1_56 | EOB, WED 11/23/11 | EOB, WED 11/30/11 | Only
 157 | EOB, FRI 12/02/11 | EOB, THU 12/08/11 | Only

Required output
Code:
 153 | EOB, WED 10/19/11 | EOB, FRI 10/21/11 | asded
 154 | EOB, WED 10/26/11 | EOB, THU 10/27/11 | Only
 155 | EOB, TUE 11/08/11 | EOB, TUE 11/15/11 | Guide
 157 | EOB, FRI 12/02/11 | EOB, THU 12/08/11 | Only

od -bc output
Code:
 > od -bc in.txt
0000000 040 061 137 065 062 040 174 040 105 117 102 054 040 124 125 105
               1   _   5   2       |       E   O   B   ,       T   U   E
0000020 040 061 060 057 061 061 057 061 061 040 174 040 105 117 102 054
               1   0   /   1   1   /   1   1       |       E   O   B   ,
0000040 040 115 117 116 040 061 060 057 061 067 057 061 061 040 174 040
               M   O   N       1   0   /   1   7   /   1   1       |
0000060 141 163 144 145 144 012 040 061 065 063 040 174 040 105 117 102
           a   s   d   e   d  \n       1   5   3       |       E   O   B
0000100 054 040 127 105 104 040 061 060 057 061 071 057 061 061 040 174
           ,       W   E   D       1   0   /   1   9   /   1   1       |
0000120 040 105 117 102 054 040 106 122 111 040 061 060 057 062 061 057
               E   O   B   ,       F   R   I       1   0   /   2   1   /
0000140 061 061 040 174 040 141 163 144 145 144 012 040 173 143 157 154
           1   1       |       a   s   d   e   d  \n       {   c   o   l
0000160 157 162 072 043 146 146 060 060 060 060 175 134 052 052 052 052
           o   r   :   #   f   f   0   0   0   0   }   \   *   *   *   *
0000200 052 052 052 052 134 052 173 143 157 154 157 162 175 040 174 040
           *   *   *   *   \   *   {   c   o   l   o   r   }       |
0000220 173 143 157 154 157 162 072 043 146 146 060 060 060 060 175 103
           {   c   o   l   o   r   :   #   f   f   0   0   0   0   }   C
0000240 157 144 145 173 143 157 154 157 162 175 040 174 040 173 143 157
           o   d   e   {   c   o   l   o   r   }       |       {   c   o
0000260 154 157 162 072 043 146 146 060 060 060 060 175 106 162 145 145
           l   o   r   :   #   f   f   0   0   0   0   }   F   r   e   e
0000300 172 145 173 143 157 154 157 162 175 040 174 040 173 143 157 154
           z   e   {   c   o   l   o   r   }       |       {   c   o   l
0000320 157 162 072 043 146 146 060 060 060 060 175 134 052 052 052 052
           o   r   :   #   f   f   0   0   0   0   }   \   *   *   *   *
0000340 052 052 052 052 052 052 052 052 052 052 052 052 052 052 052 052
           *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *
0000360 134 052 173 143 157 154 157 162 175 012 040 061 065 064 040 174
           \   *   {   c   o   l   o   r   }  \n       1   5   4       |
0000400 040 105 117 102 054 040 127 105 104 040 061 060 057 062 066 057
               E   O   B   ,       W   E   D       1   0   /   2   6   /
0000420 061 061 040 174 040 105 117 102 054 040 124 110 125 040 061 060
           1   1       |       E   O   B   ,       T   H   U       1   0
0000440 057 062 067 057 061 061 040 174 040 117 156 154 171 012 040 061
           /   2   7   /   1   1       |       O   n   l   y  \n       1
0000460 065 064 137 063 040 134 134 040 174 040 116 117 117 116 054 040
           5   4   _   3       \   \       |       N   O   O   N   ,
0000500 124 110 125 122 123 040 061 061 057 063 057 061 061 040 134 134
           T   H   U   R   S       1   1   /   3   /   1   1       \   \
0000520 040 174 040 116 057 101 040 134 134 040 174 040 120 154 141 156
               |       N   /   A       \   \       |       P   l   a   n
0000540 156 145 144 040 012 040 061 065 064 137 064 040 134 134 040 174
           n   e   d      \n       1   5   4   _   4       \   \       |

please answer this!!!

Last edited by Scott; 11-04-2011 at 05:27 AM.. Reason: Code tags
# 14  
Old 11-04-2011
is this not working ?

Code:
 
nawk '/^[0-9][0-9][0-9] /' in.txt

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