Manipulating a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulating a text file
# 1  
Old 06-23-2007
Data Manipulating a text file

hey guys, need ur expert help. m a core banker got stuck in someting techie and cant find a solution

have manged to extract a file from oracle apps in a format that looks something like this...

REC- A b c d x


INV- A b
REC- A b c x
000

INV- a b

what is need to do is something like this

read line by line and delete all lines dat dont start wit REC- or INV-
pick up only the first 70 chars of INV-

Can you pleaaaaasseeee help.. I 'll be indebted.. thanks so much
# 2  
Old 06-23-2007
Code:
awk '/REC/ {print}
     /INV/ {print substr($0,1,70) }
' "file"

# 3  
Old 06-23-2007
wow!!!

u mean its this simple.. thank u so much... Smilie
just one query.. would this command automatically read each line and identify if the line starts with REC- or INV-

and secondly "file" is the filename right..

Last edited by komalkg; 06-23-2007 at 01:26 PM..
# 4  
Old 06-23-2007
A little bit more secure:
Code:
awk '/^REC-/ {print}
     /^INV-/ {print substr($0,1,70) }
' "file"

# 5  
Old 06-23-2007
Quote:
Originally Posted by komalkg
just one query.. would this command automatically read each line and identify if the line starts with REC- or INV-
yes. To learn more about this command, type man awk.
Quote:
and secondly "file" is the filename right..
yes


@aigles:thanks
# 6  
Old 06-23-2007
sed+awk

cat filename | sed '/XXX\|YYY/!d' | awk '
{
if ($0 ~ /YYY/)
print substr($0,1,70)
else
print
}'
# 7  
Old 06-24-2007
Quote:
Originally Posted by summer_cherry
cat filename | sed '/XXX\|YYY/!d' | awk '
{
if ($0 ~ /YYY/)
print substr($0,1,70)
else
print
}'
please take a look here
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python for text manipulating

Dear All, I am trying to write a python code for reading a fixed number of lines from a big file then save those pieces into another file as columns. I think sample file is necessary for understanding: Sample Input file: Epi. dist.(km)= 0.8100E+02 0.7466E-07 0.4942E-07 0.7133E-07 ... (10 Replies)
Discussion started by: johankor
10 Replies

2. Shell Programming and Scripting

need help on manipulating a file

Hi, I need a shell/command to achieve this task. I've a delimited unloaded file from oracle in a scrambled format as shown below with many blank lines in it, I'm just trying to tailor it in a format that would be compatible to view and load it to a IDS db. Here is the problem ... (1 Reply)
Discussion started by: divak
1 Replies

3. Shell Programming and Scripting

Manipulating csv file

We need to convert a field in a csv file which is in cents to dollars.(divide by 100) in our shell script. Can some body help me? (3 Replies)
Discussion started by: Deepthz
3 Replies

4. Shell Programming and Scripting

Manipulating a file

Hi everybody, I need an urgent help with a BASH script. I have file which contains (besides the other data) the lines with the following structure identified by with keyword PCList: <PARAMETER NAME="PCList" TYPE="LIST_STRUCTURE" MODEL="{,}" ... (1 Reply)
Discussion started by: sameucho
1 Replies

5. Shell Programming and Scripting

Manipulating the etc/passwd file with sed

How can i use sed to extract the user name and home directory from the /etc/passwd/ file on my server. (11 Replies)
Discussion started by: Pauline mugisha
11 Replies

6. Shell Programming and Scripting

parsing a file and manipulating the contents

Hi I have a text file as follows BOB 14/14 TOM 94/94 SAM 3/3 CRIS 13/13 TOM 6/6 CRIS 27/27 SAM 2/2 JACK 25/25 CRIS (6 Replies)
Discussion started by: shellignorant
6 Replies

7. Shell Programming and Scripting

csh: manipulating text files - please help!

Hi All, I am trying to manipulate a text file in a csh script I am writing. I just started scripting a few months ago and have NO idea how to get this to work. My ultimate goal is to turn a text file that looks like this: 4 ep2d_diff_mddw_20_p2-MOD err 128 128 64 62 52611737 2 ... (3 Replies)
Discussion started by: Torinator
3 Replies

8. UNIX for Dummies Questions & Answers

Help!! manipulating file

Hi all, I need help manipulating the file below. Here is what I needed to do. First, I have to replace INSUPD to DELETE. Then I need to change the content of the file around by flipping the contents in the file from the bottom to the top (start from "CMD") How should I attack this? Here... (2 Replies)
Discussion started by: sirrtuan
2 Replies

9. Solaris

Manipulating File

Help...please. I have a log that contains Warning Authentication Failed: User GHDT88998HS doesn't exit: The User GHDT88998HS could not be found Mar 22, 2008 5:22:22AM com.hometel.ttm.auth.userlogin. about maybe a thousand entries failed user acct message How can I grab just the username... (2 Replies)
Discussion started by: rivendell500
2 Replies

10. UNIX for Advanced & Expert Users

Manipulating output file

I have a file containing two fields, Name and Time, with about 57 lines in this file. I am struggling to create a loop that will cut out the first ten lines of this file and echo it to the screen. Can anybody help me please. (1 Reply)
Discussion started by: mariner
1 Replies
Login or Register to Ask a Question