Finding a string with another string is found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a string with another string is found
# 1  
Old 11-01-2010
Finding a string with another string is found

finding a string with another string is found

EX:

abs c/-

i want to find /-, then copy abs. i know it's easy use awk, but my problem is the substr syntax.

substr($2,2,2) will give me /-

but the conflict is /- is not always the second characted of the second string.
# 2  
Old 11-01-2010
Would this work?
Code:
awk '/\/-/{print $1}' file

# 3  
Old 11-01-2010
thanks! but will it give the same results with:

cat file1 | awk '/\/-/{print $1}' >> file2
# 4  
Old 11-01-2010
Yes the cat is superfluous. It is equivalent to:
Code:
awk '/\/-/{print $1}' file1 >> file2

# 5  
Old 11-01-2010
it worked! thanks!

but i do have a follow up inquiry. my raw data is like this:

123 456 ABS-05
UNIX C/-


i need a result like this:

UNIX 123 456


i used awk' ((substr...) to get 123 456. but i cant put the syntax you gave me to have UNIX. thanks!
# 6  
Old 11-01-2010
Hi, hat is the criterion for your follow up? The first two words on the previous line plus the first word on the current line?
# 7  
Old 11-01-2010
yes, i cant use substr and your syntax all together. thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add NA When String is not found

I am searching for these patterns in my file between commas, when I dont find a pattern match I would Like to add NA. awk '/Device ID:/ || /address:/ || /Interface:/ || /VLAN:/ || /Platform:/ || /Software/ {print $0,"NA"}' $tempdir/shcdpnedet > $tempdir/newtt (9 Replies)
Discussion started by: dis0wned
9 Replies

2. Shell Programming and Scripting

Get 20 lines above string found, and 35 below string

i want to search a log for a string. when that string is found, i want to grab the a set number of lines that came before the string, and a set number of lines that come after the string. so if i search for the word "Error" in the /var/log/messages file, how can I output the 20 lines that came... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
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. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

8. Solaris

Can't install Unicode::String due to String.so not found

CPAN.pm: Going to build G/GA/GAAS/Unicode-String-2.09.tar.gz Checking if your kit is complete... Looks good Writing Makefile for Unicode::String cp String.pm blib/lib/Unicode/String.pm cp lib/Unicode/CharName.pm blib/lib/Unicode/CharName.pm /usr/bin/perl /usr/perl5/5.8.4/lib/ExtUtils/xsubpp... (5 Replies)
Discussion started by: PatrickBaer
5 Replies

9. Shell Programming and Scripting

help with finding a string

Hello folks I have a text file abcd.txt and has a line starting with number '8'. I have a string in this line starting at position 'a' to position 'b' also this string is a number and have to be reduced by 1. there is also a problem that it has to be padded with zeros to make the string... (2 Replies)
Discussion started by: sandyg
2 Replies

10. Shell Programming and Scripting

Display only found string

Is there a way for grep to output only the found string and not the whole line? I have a ksh script which reads in a file and loops through every line looking up on a grep -f list. For it to only display only the string found i pass this to awk as a variable and loop through the list file using... (5 Replies)
Discussion started by: Cranie
5 Replies
Login or Register to Ask a Question