GREP/SED - get string in a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GREP/SED - get string in a line
# 1  
Old 02-21-2011
Java GREP/SED - get string in a line

Hi,

I simply try to get a string in a line but I do smth. wrong. Hopfefully you can help me Smilie

tried smth like:
Code:
 
ggrep -Eo " /folder1/folder2/folder3/* end" get_info_file > temp.file

I played a bit around but could not specify the end string command...

So this is the get_info_file:
Quote:
lines not needed....
start_1 /folder1/folder2/folder3/file_a end_1
start_2 /folder1/folder2/folder3/folder4/file_b end_2
start_3 /folder1/folder2/folder3/folder4/file_c end_3
lines not needed....
...
needed result:
Quote:
/folder1/folder2/folder3/file_a
/folder1/folder2/folder3/folder4/file_b
/folder1/folder2/folder3/folder4/file_c
so one idea is to find a string until space which includes /folder1/* without previous words, which are also seperated by space.

thanks a lot and best regards...
# 2  
Old 02-21-2011
Show us what contains your :

Code:
get_info_file

# 3  
Old 02-21-2011
Code:
 
grep  "/folder1/folder2/folder3/"  INPUTFILE| cut -d" " -f2


Last edited by panyam; 02-21-2011 at 10:26 AM.. Reason: specified the file name in bold
This User Gave Thanks to panyam For This Post:
# 4  
Old 02-21-2011
@ctsgnb
I posted what it contains and it's in QUOTES - you may have another look. Thanks

@panyam
I had a try - thanks for the fast response
using:
Code:
 
grep  "/folder1/folder2/folder3/" rem | cut -d" " -f2 INPUTFILE


Works perfect! Thanks a lot
# 5  
Old 02-21-2011
@panyam
I had a try - thanks for the fast response
using:
Code:
 
grep  "/folder1/folder2/folder3/" rem | cut -d" " -f2 INPUTFILE

It suppose to be:

Code:
 
grep  "/folder1/folder2/folder3/" INPUTFILE | cut -d" " -f2

Sorry , but here "rem" is my inputfile name and pasted as it is!!!
This User Gave Thanks to panyam For This Post:
# 6  
Old 02-21-2011
Code:
awk '/\/folder1\/folder2\/folder3\//{print$2}' get_info_file >/tmp/grepoutput

or nawk on solaris
Code:
nawk '/\/folder1\/folder2\/folder3\//{print$2}' get_info_file >/tmp/grepoutput


Last edited by ctsgnb; 02-21-2011 at 10:46 AM..
This User Gave Thanks to ctsgnb For This Post:
# 7  
Old 02-22-2011
Yeah now i get this... was searching for remove command :-)
But worked also with rem command like before and not having rem file...

So this is the final solution for me and works:
Code:
 
grep  "/folder1/folder2/folder3/" INPUTFILE | cut -d" " -f2 > tmp_grep

+thanks!

---------- Post updated at 05:26 PM ---------- Previous update was at 03:40 PM ----------

one more question regarding to the "cut delimiter" option.

man page tells me i can use multybyte delimiters, but i'm not able to...

example:
STRING.txt bla spam...
wished result:
STRING // so delimiter is .txt

I tried delimiter ".txt" - did not work
I tried delimiter "." - worked
so can anyone tell me how i can use more characters as delimiter? Also tried ' instead of "

thanks guys
& girls for sure

---------- Post updated 22nd Feb 2011 at 01:32 PM ---------- Previous update was 21st Feb 2011 at 05:26 PM ----------

Found it out...

Code:
grep "/folderA/folderB" INPUT_FILE | cut -d " " -f2 | cut -d "." -f1,2 > OUTPUT_FILE

cut -d " " -f2 // ensures to get colums seperated by spaces and chooese second
cut -d "." -f1,2 // seperate above through dots and use first and second column
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

2. Shell Programming and Scripting

Using sed to get text between a string and next line after another string

Hi folks! I'm trying to get a part of a text inside a text file (sudoers actually) but I'm having trouble. Here is an example of a text: Cmnd_Alias DUMMY = /bin/ls /bin/car /usr/bin/whatever Cmnd_Alias TARGET = test test test test test \ ... (6 Replies)
Discussion started by: leandrorius
6 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

5. Shell Programming and Scripting

Grep a string and write a value to next line of found string

Hi, I have two variables x and y. i need to find a particular string in a file, a workflow name and then insert the values of x and y into the next lines of the workflow name. basically it is like as below wf_xxxxxx $$a= $$b= $$c= figo $$d=bentley i need to grep the 'wf_xxxx' and then... (6 Replies)
Discussion started by: angel12345
6 Replies

6. Shell Programming and Scripting

grep on string and printing line after until another string has been found

Hello Everyone, I just started scripting this week. I have no background in programming or scripting. I'm working on a script to grep for a variable in a log file Heres what the log file looks like. The x's are all random clutter xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx... (7 Replies)
Discussion started by: rxc23816
7 Replies

7. Shell Programming and Scripting

String: Grep / SED for multy line search

Hi, At first I want to please you to provide the solution with grep/sed if possible. :cool: File looks like: wished result: so I want in a new file BLUE@@RED string from first line like: grep "/folder_start" cs_src > tmp1 string from second line: grep "/main" cs_src... (14 Replies)
Discussion started by: unknown7
14 Replies

8. Shell Programming and Scripting

Sed or Grep to delete line containing patter plus extra line

I'm new to using sed and grep commands, but have found them extremely useful. However I am having a hard time figuring this one out: Delete every line containing the word CEN and the next line as well. ie. test.txt blue 324 CEN green red blue 324 CEN green red blue to produce:... (2 Replies)
Discussion started by: rocketman88
2 Replies

9. Shell Programming and Scripting

Grep a string and print a string from the line below it

I know how to grep, copy and paste a string from a line. Now, what i want to do is to find a string and print a string from the line below it. To demonstrate: Name 1: ABC Age: 3 Sex: Male Name 2: DEF Age: 4 Sex: Male Output: 3 Male I know how to get "3". My biggest problem is to... (4 Replies)
Discussion started by: kingpeejay
4 Replies

10. UNIX for Dummies Questions & Answers

grep a string in a line using sed

Hi, I'm trying to grep a string in a line using sed. My original data looks like this: MRTG$ grep -i "System" $file <H1>Traffic Analysis for 15 -- sERITHC3602.t-mobile.co.uk</H1> <TABLE> <TR><TD>System:</TD> <TD>sERITHC3602 in </TD></TR> <TR><TD>Maintainer:</TD> <TD></TD></TR>... (4 Replies)
Discussion started by: viadisky
4 Replies
Login or Register to Ask a Question