how to extract the data ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to extract the data ?
# 8  
Old 06-16-2009
Try this:

Code:
awk -F" - " '{gsub("[(\.]","")}{print $2}'

You can place "weird" characters within the brackets [], special characters must be escaped with a backslash.
# 9  
Old 06-16-2009
Quote:
Originally Posted by Franklin52
Try this:

Code:
awk -F" - " '{gsub("[(\.]","")}{print $2}'

You can place "weird" characters within the brackets [], special characters must be escaped with a backslash.

Hi Franklin,

the expected output should be the whole field as what it is.

eg. FGI-LOM3100R \ LOM FGI REPORT (.

with your codes, the result is something like
FGI-LOM3100R LOM FGI REPORT
which is inaccurate.

again how can we extract the 3rd field totally without being affected by the chars within the field as delimiters?

i've tried using awk " - " but its giving me inaccurate answers if the field has a " - " within.

eg,


data: ID 123 - testing
output using awk comamnd: testing
desired output: testing



data: ID 456 - abc-abc.(
output using awk comamnd: abc-abc.(
desired output: abc


data: ID 7111 - abc - def
output using awk comamnd: def
desired output: abc - def

Last edited by uxnoob; 06-16-2009 at 11:34 PM..
# 10  
Old 06-17-2009
I've misread the question, try this:

Code:
awk -F" - " '{print $2}' file

Regards
# 11  
Old 06-17-2009
Code:
awk '{$1="";$2="";$3=""; print }' input_file.txt | sed 's/^[ ]*//g'

# 12  
Old 06-17-2009
Hi Guys,

Thanks for the replies so far. Haven't really quite hit the nail on the head yet though

Quote:
Originally Posted by Franklin52
I've misread the question, try this:

Code:
awk -F" - " '{print $2}' file

Regards

data: ID 7111 - abc - def
output using awk -F" - " '{print $2}' file comamnd: abc
desired output: abc - def
# 13  
Old 06-17-2009
its simple...
Code:
cat inputfile | cut -d"-" -f2-

# 14  
Old 06-17-2009
MySQL

Quote:
Originally Posted by rakeshawasthi
its simple...
Code:
cat inputfile | cut -d"-" -f2-

fantastic. Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

2. Shell Programming and Scripting

Help with File Data Extract

Hello, Hope you are doing fine. I have been struggling with it for some time now and I would really appreciate your help. Following is file format: Currency,Name,Date, Term USD, ABC, 2011/11/11, T0, S1, S2, S3, S4 , , ,T1, 5.6, 2.3, 6.5, 4.5 , ... (5 Replies)
Discussion started by: srattani
5 Replies

3. Shell Programming and Scripting

help with data extract script

hi, i'am trying to write a script which takes a data element from one file and searches in a certain file path and after it finds it it redirects the file names to a new file...Now i have to pick the up the last modified file's Timestamp(MMDDYY) from the files collected for each data element. ... (2 Replies)
Discussion started by: kmr023
2 Replies

4. UNIX for Dummies Questions & Answers

extract lines from data

I have a file that looks like this: >cel-miR-35 MIMAT6 C eles le UCACCGGGUGGAAACUAGCAGU >hsa-let-7a MI062 H sa UGAGGUAGUAGGUUGUAUAGUU >cel-miR-36 M007 Ca ele UCACCGGGUGAAAAUUCGCAUG >hsa-let-7b MI63 Hmo sns le UGAGGUAGUAGGUUGUGUGGUUI would like to extract all the lines that start with... (7 Replies)
Discussion started by: jdhahbi
7 Replies

5. Shell Programming and Scripting

XML data extract

Hi all, I have the following xml document : <HEADER><El1>asdf</El1> <El2>3</El2> <El3>asad</El3> <El4>asasdf</El4> <El5>asdf</El5> <El6>asdf</El6> <El7>asdf</El7> <El8>A</El8> <El9>0</El9> <El10>75291028141917</El10> <El11>asdf</El11> <El12>sdf</El12> <El13>er</El13> <El14><El15>asdf... (1 Reply)
Discussion started by: nthed
1 Replies

6. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

7. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

8. Shell Programming and Scripting

extract data from a data matrix with filter criteria

Here is what old matrix look like, IDs X1 X2 Y1 Y2 10914061 -0.364613333 -0.362922333 0.001691 -0.450094667 10855062 0.845956333 0.860396667 0.014440333 1.483899333... (7 Replies)
Discussion started by: ssshen
7 Replies

9. Shell Programming and Scripting

extract data from file

I m new to shell scripting & i need a help.... i have file like.... Name := sachin address:=something phone:=111 ... Note: There might be or not space between Name & := and between := & sachin. I need to extract the data from each line of file as var1=Name value1=sachin same for... (13 Replies)
Discussion started by: ps_sach
13 Replies

10. UNIX for Dummies Questions & Answers

Extract data correction???

Hi I have file "test.txt" i need to extract the data as below from this file. /home/cvs/gkc ->awk -v RS= '{print $(NF-2),$(NF-1),$NF}' test.txt Buildfile: build.xml Buildfile: build.xml Created dir: /dist/advance/2.0.4/20060926-0413 awk: The field -1 must be in the range 0 to 199. ... (6 Replies)
Discussion started by: gkrishnag
6 Replies
Login or Register to Ask a Question