473,486 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Find string and return next string in bash

1 New Member
Hi World,

I am extracting text from an ebcdic header using dd in the cygwin environment (bash/ksh) as below in order to rename the file to something intelligent.

I'm using a specific string position here ($10) but the text I extract is sometimes in a different position in the header so I need to search for preceding text "LINE:" and then extract the next string, which is the info I'm interested in.

So - using awk or sed (or perl if need be) can anyone help me with the syntax for
'find string 'LINE:' and return next string'

Secondly, in order to avoid overwriting files I'm appending a -1, -2, -3 etc but doing a specific search for this.
In awk, how does one read a filename, check to see if there's a -x at the end, and if so, split that off and increment it by one for naming the next file.

Thanks for any tips,
Bryan.

for file in s*.00* ;
do
dd if=$file of=header conv=ascii count=1
linename=`awk '{print $10}' header`

if [ ! -e $linename".sgy" ] ; then
cp $file $linename".sgy"

elif [ -e $linename".sgy" ] && [ ! -e $linename"-1.sgy" ] ; then
cp $file $linename"-1.sgy"

etc until $linename"-4.sgy"

done
Jul 12 '06 #1
2 12818
rengaraj
168 New Member
> So - using awk or sed (or perl if need be) can anyone help me with the syntax > for 'find string 'LINE:' and return next string'

This is simple with awk. Observe:

[hector@troy ~]$ cat data-file
stuff stuff
LINE:
print me #1
stuff
stuff stuff
LINE:
print me #2
stuff
[hector@troy ~]$ awk '/LINE:/{ getline; print; }' data-file
print me #1
print me #2
Feb 18 '07 #2
rengaraj
168 New Member
>Secondly, in order to avoid overwriting files I'm appending a -1, -2, -3 etc but >doing a specific search for this.
>In awk, how does one read a filename, check to see if there's a -x at the end, >and if so, split that off and increment it by one for naming the next file.

I think I follow what you're asking, but maybe you could post a couple real examples of what you're trying to do.
Feb 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
8715
by: usgog | last post by:
I need to implement a function to return True/false whether String A contains String B. For example, String A = "This is a test"; String B = "is is". So it will return TRUE if String A includes two...
4
2525
by: Pokerkook | last post by:
Hello, If anybody could help me with this I would greatly appreciate it. Or at least tell me why I get the output of this garbage: 49 49 10 49 52
23
3546
by: Nascimento | last post by:
Hello, How to I do to return a string as a result of a function. I wrote the following function: char prt_tralha(int num) { int i; char tralha;
4
34070
by: Locusta | last post by:
Hello, I have been struggeling for replacing a string in a string. The snippet from the program below replaces the <, & and > with the XML equivalent values. In the program, I allocate space...
2
943
by: JIM.H. | last post by:
Hello, How would you search XYZ_ in a string and if exist, return next three characters after string (so, if XYZ_001, return 001), otherwise return null in C#. Thanks, Jim.
6
53668
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
1
5211
by: Jerry | last post by:
I'm new to c++, trying a simple test to read data form a txt file. I compiled with gcc version 3.4.4 20050721 (Red Hat 3.4.4-2). It didn't work as expected, getline() return with null string and...
4
1980
by: jelle | last post by:
the subject pretty much says it all. if I check a string for for a substring, and this substring isn't found, should't the .find method return 0 rather than -1? this breaks the if...
3
2485
by: yogi_bear_79 | last post by:
I'm sure I have a few things wrong here. But I am stuck on how to do a recurring search. Also my statement cin >quote; acts weird. If I enter more than one word it blows right past cin >findMe;...
0
7099
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4864
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.