To manipulate a specific line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers To manipulate a specific line
# 1  
Old 07-09-2005
To manipulate a specific line

Hi,
I would like to cut a specific line from a text file and then manipulate the text in that line.
For eg. below is "tmp" file.
-----------------
Tue 07/05/05 00:27:34.333
Tue 07/05/05 00:27:34.333 4 events were processed for customer 315 and will be correctly resolved when 315MERGE is run:
Tue 07/05/05 00:27:34.333 ISA ContainerID Event
Tue 07/05/05 00:27:34.333 000005225 PONU178050 VD
Tue 07/05/05 00:27:34.333 000005225 PONU178050 AE
Tue 07/05/05 00:27:34.333 000005225 PONU738873 VD
Tue 07/05/05 00:27:34.333 000005225 PONU738873 AE
------------------
In the above file, I am able to get the line no (line no: 2) of the searching string "events were processed for customer", then I would like to cut the lines in the file starting from 3rd line.

Below is my script:
------------------
#!/bin/ksh
nm=`grep -n "events were processed for customer" tmp |cut -c1-2`
echo $nm

Can anybody help me in this.


cheers,
dhiman.


Edit - ZB - Font still to large.... removed superflous SIZE tags...

Last edited by zazzybob; 07-09-2005 at 08:06 AM..
# 2  
Old 07-09-2005
Hmm... so you want to find the line that includes the text "events were processed" and then display all lines that appear below that matched line?
Code:
$ nm=`grep -n "events were processed" tmpfile`
$ echo $nm
2:Tue 07/05/05 00:27:34.333 4 events were processed for customer 315 and will be correctly resolved when 315MERGE is run:
$ sed -n "$(( `echo $nm | cut -d: -f1` + 1 )),$ p" tmpfile
Tue 07/05/05 00:27:34.333 ISA ContainerID Event
Tue 07/05/05 00:27:34.333 000005225 PONU178050 VD
Tue 07/05/05 00:27:34.333 000005225 PONU178050 AE
Tue 07/05/05 00:27:34.333 000005225 PONU738873 VD
Tue 07/05/05 00:27:34.333 000005225 PONU738873 AE
$

Cheers
ZB
# 3  
Old 07-10-2005
for gun sed
Code:
sed '0,/events were processed/d' tmpfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to manipulate string in line?

Hello, I looked up on google but do not know from which point to start... I am under ubuntu 18 bionic and Mainfile consists of 25K lines MainFile: Test,AAEE9FED3, GGBBDD DD AA X2d Moscow 112233445566aaBBccPPdddEE Test,AAEE9FED3, GG33DD s00022 Leningrad 11298932566aaBBccPPdddEE... (8 Replies)
Discussion started by: baris35
8 Replies

2. Shell Programming and Scripting

Manipulate XML File Continous STRING by each Order Line using SHELL

heres sample File: <?xml version="1.0"?> <!DOCTYPE cXML SYSTEM "www"><cXML.............................................. <OrderRequest>USE UNIX.com</Extrinsic><Extrinsic name="UniqueName">Peter@UNIX.com</Extrinsic><Extrinsic name="ContractingEntity">UNIX... (3 Replies)
Discussion started by: Pete.kriya
3 Replies

3. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Shell Programming and Scripting

Commenting a specific line and inserting a new line after commented line.

Hello All, I have following file contents cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line line=eeeeee and insert a new line... (19 Replies)
Discussion started by: manishdivs
19 Replies

5. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

6. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

7. Shell Programming and Scripting

perform some operation on a specific coulmn starting from a specific line

I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. eg: 50.000000 1 1 1 1000.00000 1000.00000 50000.000 19 19 3.69797533E-07 871.66394 ... (3 Replies)
Discussion started by: shashi792
3 Replies

8. Shell Programming and Scripting

Extract File line and manipulate

How can I print a section of each line in a text file. Eg CODE1 XYR Test2 10319389 CODE2 XYR Test2 10319389 CODE3 XYR Test2 10319389 CODE4 XYR Test2 10319389 CODE5 XYR Test2 10319389 First thing that would be nice would a new file like, awk sed and substring may help but can't figure it... (6 Replies)
Discussion started by: kelseyh
6 Replies

9. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

10. Shell Programming and Scripting

manipulate data with specific format

Hi everybody: I have a problem with how I have to manipulate the data which have specific format like this: 249. 0.30727021E+05 0.30601627E+05 0.37470780E-01 -0.44745335E+02 0.82674536E+03 248. 0.30428182E+05 0.30302787E+05 0.40564921E-01 -0.45210293E+02 ... (5 Replies)
Discussion started by: tonet
5 Replies
Login or Register to Ask a Question