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
# 1  
Old 01-30-2015
I want to grep the text value in UNIX shell file

Hi Guys,

I want to grep the text/code value in my shell script.

Sample Code:
Code:
-H "fjkldj skdfjk2342 kj s2323"

Here, the code value is in double quotes after -H. This value I have to pic and put it in variable to pass a parameter value.

Can any one help me on this!

Thanks in advance!

Regards,
Lakshman

Last edited by Franklin52; 01-30-2015 at 07:32 AM.. Reason: Please use code tags
# 2  
Old 01-30-2015
Hello Lakshman,

Welcome to forums, please use code tags for commands/codes/inputs which you are using in your posts as per forum rules. You can go through the rules of forum in following link too.
https://www.unix.com/misc.php?do=cfrules

For your requirement following may help you in same.
Code:
awk '{match($0,/\".*\"/);print substr($0,RSTART+1,RLENGTH-2)}'  Input_file

Output will be as follows, you can take this into a variable as per your need too.
Code:
fjkldj skdfjk2342 kj s2323

Thanks,
R. Singh

Last edited by RavinderSingh13; 01-30-2015 at 05:05 AM.. Reason: Added rules link
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 01-30-2015
Thanks for your reply, but there are many code values in my script, I want exactly after -H code value only.
# 4  
Old 01-30-2015
Hello Lakshman,

From your post I am understanding you need to catch string -H "string", if this is the case please use following, if not please give us sample inputs and exact required output for same, we can help you in same.
Code:
awk '{match($0,/\-H \".*\"/);print substr($0,RSTART+4,RLENGTH-5)}'  Input_file

Output will be as follows.
Code:
fjkldj skdfjk2342 kj s2323

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 01-30-2015
Try also
Code:
awk -F\" '$1~/-H/ {print $2}' file
fjkldj skdfjk2342 kj s2323

# 6  
Old 02-02-2015
along with the below code a complete shell script is there. But I need to grep the value only after -H"asdfgsdfgsdfgg5345dg4545" with in double quotes.

Code:
/sfd/fgf/ghg/dsfds/bin/gdsfgsdfg "/fdsf/dfg/dfgh/gfhfgh/log/ghfghfgh/" -w "sdfgsdfgsdfg"
"-fgsdfgsdfg -r\"dfgsdfg.txt\" -H"asdfgsdfgsdfgg5345dg4545" -e5 -e12
-dfsgsdf -dfgdfg -dfgdfg -sgdfgsdfg -gfdfgfhfgh -dsfgdsfgsdfg -sdfgdfg


Can any one help me on this?

Last edited by lakshmanraok; 02-02-2015 at 06:46 AM..
# 7  
Old 02-02-2015
Code:
sed -n 's/.*-H *"\([^"]*\)".*/\1/p' file

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