Need Help with AWK or SED (Newbie)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help with AWK or SED (Newbie)
# 1  
Old 06-18-2008
Need Help with AWK or SED (Newbie)

Hello,

I have a text file in below format, how do I put a header and assign field names to the file with either AWK or SED

STRT~ VA ~23606 ~TM14~8506~1485 (page 1)

STRT~ VA ~23662 ~TM17~8362~1783 (page 2)
STRT~ VA ~23662 ~TM17~8362~1783
STRT~ VA ~23662 ~TM17~8362~1783
STRT~ VA ~23662 ~TM17~8362~1783

result:

------------------HEADER-------------------

--A----B------C------D------E-----F----(Field names)
STRT~ VA ~23606 ~TM14~8506~1485 (page 1)

------------------HEADER-------------------
--A----B------C------D------E-----F----(Field names)
STRT~ VA ~23662 ~TM17~8362~1783 (page 2)
STRT~ VA ~23662 ~TM17~8362~1783
STRT~ VA ~23662 ~TM17~8362~1783
STRT~ VA ~23662 ~TM17~8362~1783


Thank you

Last edited by udaybo; 06-18-2008 at 01:04 PM..
# 2  
Old 06-18-2008
Something like this:

Code:
awk '/page/{print "--HEADER--";print "--Fieldnames--"}1' file

Regards

Last edited by Franklin52; 06-18-2008 at 01:51 PM.. Reason: Typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed newbie question

hi all: i am trying to use sed to separate hex bytes "363834574e292c20" to "36 38 34 57 4e 29 2c 20". i used the following script (googled) and i got "3 63 83 45 74 e2 92 c2 0". how could i modify the script to meet my needs? thanks (8 Replies)
Discussion started by: ipfreak
8 Replies

2. Shell Programming and Scripting

sed newbie scripting assistance

Howdy folks, I'm trying to craft a log file summarisation tool for an application that creates a lot of duplicate entries with only a different suffix to indicate point of execution. I thought I'd gotten close but I'm clearly missing something. Here's a genericized version: A text_file... (3 Replies)
Discussion started by: mthespian
3 Replies

3. Shell Programming and Scripting

newbie -- please help: sed

Hi I am trying to setup a sed script that will rename all files in a folder to their date and time stamp. eg: xxxxx.jpg xxxxx12.jpg xxxxx14.jpg they need to be renamed to upstairs `date +%Y%m%d`.jpg They have no metadata, so cannot use exif, will need to use sed. Thanks... (2 Replies)
Discussion started by: akmodi
2 Replies

4. UNIX for Dummies Questions & Answers

Sed Newbie Question

Hello everyone I could really need some help. I want to rename : with dot. But the problem is that i don't want to touch the hours like 12:00 but i want to change AD:FG with AD.FG. I'm thinking something like : to . I don't know if i explain it corrrectly but i could use some help Thanks... (20 Replies)
Discussion started by: zoe
20 Replies

5. Shell Programming and Scripting

Help with awk for a newbie

Hi there, greetingt to everybody. I have configured syslog-ng to get messages over UDP saving logs into a text file, it works fine. I need to store the content of this file in several files depending from some criteria that I try to explain you with some examples : Suppose the content of my log... (5 Replies)
Discussion started by: capnino
5 Replies

6. Shell Programming and Scripting

SED question: newbie here.

Hello... I wanted to figure out how to remove the 1st instance of a comma from a file.. 100+ line file ------------- 'test1' ,'dudes are cool' <-- remove comma from first instance of comma in file ,'cool dude' ,'bbbbbb' I tried everything from cat jigar|tr , >1.txt to cat jigar|sed... (2 Replies)
Discussion started by: jigarlakhani
2 Replies

7. Shell Programming and Scripting

Need help with AWK (newbie)

Hello all I have a file with below data, I need to add a third column as XXXX if the first coloumn (H180620081) last number is "1" and YYYY if the first coloumn last number is "2" Can it be done with AWK, I would appreciate if anyone could help me ou with this. H180620081 31310 ... (11 Replies)
Discussion started by: udaybo
11 Replies

8. Shell Programming and Scripting

SED Newbie

I'm trying to figure out how to basically replace a line in a text file using Sed. Here's what I need sed to do: I have a file with passwords that are in use. Each month the passwords need to be swapped out with passwords stored in another file. I want to use Sed (or Awk ... or possibly both)... (3 Replies)
Discussion started by: cpslo09
3 Replies

9. Shell Programming and Scripting

awk newbie

I would like to parse a file and use each record to create a unique file where the name of the file created is taken from the 3rd field. Example: here are 3 records. 000007 0110 07-0001583 20060802132213 20060801112601 000007 0110 07-0001584 ... (4 Replies)
Discussion started by: zoo591
4 Replies

10. Shell Programming and Scripting

Newbie using sed in a shell script

I'm sure this is an easy one but I can't seem to get it working. Given the following: for oldName in `ls *.JPG` ;do newName=<confusion here. how to make sed perform 's/.JPG/_thumb.JPG/g' operation on $oldName> done Could someone show me what I'm doing wrong? Thanks Ken (1 Reply)
Discussion started by: ktoz
1 Replies
Login or Register to Ask a Question