I want to grep the text value in UNIX shell file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I want to grep the text value in UNIX shell file
# 8  
Old 02-02-2015
Hello lakshmanraok,

Following may help you in same.
Code:
echo -H\"asdfgsdfgsdfgg5345dg4545\" | awk '{match($0,/H\".*\"/);print substr($0,RSTART,RLENGTH)}'
OR
awk '{match($0,/H\".*\"/);A=substr($0,RSTART,RLENGTH);if(A){print A}}'  Input_file

Output will be as follows.
Code:
H"asdfgsdfgsdfgg5345dg4545"


Thanks,
R. Singh

Last edited by RavinderSingh13; 02-02-2015 at 06:55 AM.. Reason: Added one more solution on same
# 9  
Old 02-02-2015
Can you please explain this command, how it works?

---------- Post updated at 06:42 AM ---------- Previous update was at 06:03 AM ----------

If I am giving this command
Code:
awk '{match($0,/-G\".*\"/);A=substr($0,RSTART,RLENGTH);if(A){print A}}' file name

I am getting value below while runing above command

Code:
-G"sdfsdg4353246dfgsdf5464" - fsdf -dsfsd -sdfsdf

Please suggest me on this.

I need only value that is with double quotes after -G
# 10  
Old 02-02-2015
Hello lakshmanraok,

Following may help you in same.
Code:
awk '{match($0,/H\".*\"/);A=substr($0,RSTART+2,RLENGTH-3);if(A){print A}}'  Input_file

Here I am matching regex match($0,/H\".*\"/) and keywords RSTART, RKENGTH will be set according to matching of regex so I am taking it's values to a variable named A and if A is NOT empty then print it. Hope this helps, you can also read man awk for more information on same.

Thanks,
R. Singh
# 11  
Old 02-02-2015
Hi Guys,

I am getting the below complete value,

Code:
a45ddfg_654dfg_fgf65_hghjhj42334" 
-t1 -t23 -tyutyu -hgjghj   -ertert -ghfgh -dfgdf -dfgdfg -ghjhj

while executing the below command:

Code:
awk '{match($0,/\-G\".*\"/);A=substr($0,RSTART+4,RLENGTH-2);if(A){print A}}' file name


the actual line in my shell script is:

Code:
/bnbn/er/hhhh12/gggg/bin/fg_fghfghfgh  
"/bnbn/hg/vbn12/xccvb/log/fgfgh_1/" 
-w "dfgd:dfgdfg:dfgdfg" 
" -ghjghjgh 
-E\"hgjghj.txt\"  
-G"a45ddfg_654dfg_fgf65_hghjhj42334" 
-t1 -t23 -tyutyu -hgjghj   -ertert -ghfgh -dfgdf -dfgdfg -ghjhj
"


but I want only the highlighted value.




thanks in advance!

Regards,
Lakshman
# 12  
Old 02-02-2015
Hello Lakshman,

I am not sure you tried my solutions in privious posts or not, following is working for me.
Code:
awk '{match($0,/G\".*\"/);A=substr($0,RSTART+2,RLENGTH-3);if(A){print A}}'  Input_file

Output is as follows.
Code:
a45ddfg_654dfg_fgf65_hghjhj42334

Thanks,
R. Singh
# 13  
Old 02-02-2015
No ...I am not getting using this command , because still i am getting some more text after the value:

Code:
a45ddfg_654dfg_fgf65_hghjhj42334 -dfgdsfg -0dfgdf -gdfg

like this, why because my code value with in another two double quotes like

Code:
" -G " sddfdfgfgdfgfg" "

below is the sample code

Code:
" -ghjghjgh 
-E\"hgjghj.txt\"  
-G"a45ddfg_654dfg_fgf65_hghjhj42334" 
-t1 -t23 -tyutyu -hgjghj   -ertert -ghfgh -dfgdf -dfgdfg -ghjhj
"

I dont know why its not showing ending with " at code value after G?

Can you suggest me on this?

Thanks in advance!

Last edited by lakshmanraok; 02-02-2015 at 09:24 AM..
# 14  
Old 02-02-2015
Code:
awk -F\" 'sub(/^.*-H *"/,"") && sub(/".*$/,"")' file
asdfgsdfgsdfgg5345dg4545

---------- Post updated at 14:54 ---------- Previous update was at 14:50 ----------

Exchange the H in above with G to get a45ddfg_654dfg_fgf65_hghjhj42334
from your sample.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies

2. 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

3. Shell Programming and Scripting

HTML code upload text file grep through shell script

I am looking for HTML code that browse text file and grep with database file then retrieve result txtfileuploaded contain 112233 115599 113366 shell code grep -F -f txtfileuploaded /data/database.txt result 112233 Mar 41$ 115599 Nov 44$ 113366 Oct 33$ attached... (2 Replies)
Discussion started by: phpshell
2 Replies

4. Shell Programming and Scripting

How to write text file data to excel using UNIX shell script?

Hi All, I have the requirement in unix shell script. I want to write the "ls -ltr" command out put to excel file as below. Input :text file data : drwxr-xr-x 5 root root 4096 Oct 2 12:26 drwxr-xr-x 2 apx aim 4096 Nov 29 18:40 drwxr-xr-x 5 root root 4096 Oct 2 12:26 drwxr-xr-x... (10 Replies)
Discussion started by: Balasankar
10 Replies

5. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

6. Shell Programming and Scripting

search text file in file if this file contains necessary text (awk,grep)

Hello friends! Help me pls to write correct awk and grep statements for my task: I have got files with name filename.txt It has such structure: Start of file FROM: address@domen.com (12...890) abc DATE: 11/23/2009 on Std SUBJECT: any subject End of file So, I must check, if this file... (4 Replies)
Discussion started by: candyme
4 Replies

7. Shell Programming and Scripting

generate tabular output from an input text file in unix shell scripting

Hi, I have the output (as below) which i want it to be in a table. For e.g. space utilization in PSE on path /logs is 0% space utilization in PSE on path /logs/tuxedo/tuxlsp is 16% space utilization in PSE on path /ldvarlsp/lsp/log is 37% space utilization in PSE on path /home is 6%... (7 Replies)
Discussion started by: pkbond
7 Replies

8. Shell Programming and Scripting

how to use data in unix text file as input to an sql query from shell

Hi, I have data in my text file something like this. adams robert ahmed gibbs I want to use this data line by line as input to an sql query which i run by connecting to an oracle database from shell. If you have code for similar scenario , please ehlp. I want the output of the sql query... (7 Replies)
Discussion started by: rdhanek
7 Replies

9. Shell Programming and Scripting

Converting Text File into XML using Unix Shell Scripts

Hi everyone, If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert a file into xml format using Unix shell scripts. The file has fields with each field having a certain number of bytes, but the fields are not delimited by anything... (10 Replies)
Discussion started by: Laud12345
10 Replies

10. UNIX for Dummies Questions & Answers

grep multiple text files in folder into 1 text file?

How do I use the grep command to take mutiple text files in a folder and make one huge text file out of them. I'm using Mac OS X and can not find a text tool that does it so I figured I'd resort to the BSD Unix CLI for a solution... there are 5,300 files that I want to write to one huge file so... (7 Replies)
Discussion started by: coppertone
7 Replies
Login or Register to Ask a Question