Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to customise a file 1

Status
Not open for further replies.

adimstec

IS-IT--Management
Nov 27, 2002
52
FR
Hi,

I have to find a solution regarding this isuue

I have a file with the contains as this :


Part1

x;1;2
y;5;6

Part2

h;6;7
j;8;9

I would like to have the output like this

Part1;x;1;2
Part1;y;5;6
Part2;h;6;7
Part2;j;8;9

Any help will be appreciate
, Thanx
 
Hi

Code:
sed -n '/;/{G;s/\(.*\)\n\(.*\)/\2;\1/p;d};/./h' /input/file
Tested with GNU [tt]sed[/tt].
Code:
awk -F';' 'NF==1{p=$1}NF==3{print p";"$0}' /input/file
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Thankx ..but I tried it but it didn't worked..maybe I miss something
 
Hi

What about giving us some details ?
[ul]
[li]Your [tt]sed[/tt] implementation and version.[/li]
[li]Your [tt]awk[/tt] implementation and version.[/li]
[li]Your operating system name and version.[/li]
[li]Received error message if any.[/li]
[li]Received incorrect output if any.[/li]
[/ul]


Feherke.
 
Hi,

AIX 5.3 ML 7

Sed and Awk exists but I do not know the version

When I issue the awk example , I have no output
 
Hi

Are you sure, your sample input file is correct ?

Let us try to make the condition less restrictive :
Code:
awk -F';' 'NF==1{p=$1}NF[highlight]>1[/highlight]{print p";"$0}' /input/file

Feherke.
 
yes ...great ..this works ! Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top