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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Field seperator within awk 1

Status
Not open for further replies.

scor6800

Programmer
Oct 9, 2007
5
GR
Hi,
this is my 1st question.
I have a file seperated by " ".
I want to say that if my 1st field match to a specific string then
Change FS to "/" and take the last field.
Then change again the FS to " ".

The following doesn't work:
BEGIN{FS=" "}
{if ($1 ~ "DDL")
{FS="\/"; print $NF; FS=" "}
else {print $0}
}

A line example is this
INPUT_DDL_FNAME01 /EuroCards/dict/CutDuplicates.ddl

Any help would be appreciated
 
Hi

[ol]
[li]Do not escape the forward slash ( / ).[/li]
[li]After changing the field separator force the re-parsing of the record.[/li]
[/ol]
Code:
BEGIN {
  FS=" "
}
{
  if ($1 ~ "DDL") {
    FS="/"; [red]$0=$0;[/red] print $NF; FS=" "[red]; $0=$0[/red] 
  } else {
    print $0
  }
}

Feherke.
 
$0=$0 !!!
I could never think of it by myself.
Thank you very much.
It worked fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top