sed - how to change columns 
Author Message
 sed - how to change columns

Sorry about the simple question, but I'm a newbie with sed/awk and still know a
little bit of the vi ;-(((

I just want to change to columns among an TAB:
ANTI_CIH.EXE<TAB>005a74cc
ACCSTAT.EXE<TAB>005a8820
ACCSTAT.EXE<TAB>005a8821
WINNT/Profiles/SRBPEF/Eigene Dateien/Privat/Fehlermeldung.exe<TAB>001fb853

should look like:
005a74cc<TAB>ANTI_CIH.EXE
005a8820<TAB>ACCSTAT.EXE
005a8821<TAB>ACCSTAT.EXE
001fb853<TAB>WINNT/Profiles/SRBPEF/Eigene Dateien/Privat/Fehlermeldung.exe

Please remember the space in the forth line, so that in awk $1 $2 don't work.
Ther may be also additional blanks in the file-Name ( Win... )

Thanks in advance,
Tobias.



Tue, 06 Jan 2004 02:34:24 GMT  
 sed - how to change columns
...

Quote:
>I just want to change to columns among an TAB:
>ANTI_CIH.EXE<TAB>005a74cc
>ACCSTAT.EXE<TAB>005a8820
>ACCSTAT.EXE<TAB>005a8821
>WINNT/Profiles/SRBPEF/Eigene Dateien/...exe<TAB>001fb853

>should look like:
>005a74cc<TAB>ANTI_CIH.EXE
>005a8820<TAB>ACCSTAT.EXE
>005a8821<TAB>ACCSTAT.EXE
>001fb853<TAB>WINNT/Profiles/SRBPEF/Eigene Dateien/....exe

>Please remember the space in the forth line, so that in awk $1 $2 don't
work.
>Ther may be also additional blanks in the file-Name ( Win... )

As long as there aren't TAB characters in the filenames, switch awk's
default FS to an explicit single TAB, and change OFS to a single TAB as
well.

BEGIN { OFS = FS = "\t" }
{ print $2, $1 }

If you have perverse filenames with embedded TABs, you need to use something
more complicated.

BEGIN { OFS = "\t" }
{ match($0, /\t/)
  print substr($0, RSTART + RLENGTH), substr($0, 1, RSTART - 1) }

If you're using gawk, there's an easier approach.

{ print gensub(/^([^\t]*)\t(.*)$/, "\\2\t\\1", 1, $0) }



Tue, 06 Jan 2004 02:51:06 GMT  
 sed - how to change columns


Quote:
>Sorry about the simple question, but I'm a newbie with sed/awk and still know a
>little bit of the vi ;-(((

>I just want to change to columns among an TAB:
>ANTI_CIH.EXE<TAB>005a74cc
>ACCSTAT.EXE<TAB>005a8820
>ACCSTAT.EXE<TAB>005a8821
>WINNT/Profiles/SRBPEF/Eigene Dateien/Privat/Fehlermeldung.exe<TAB>001fb853

>should look like:
>005a74cc<TAB>ANTI_CIH.EXE
>005a8820<TAB>ACCSTAT.EXE
>005a8821<TAB>ACCSTAT.EXE
>001fb853<TAB>WINNT/Profiles/SRBPEF/Eigene Dateien/Privat/Fehlermeldung.exe

>Please remember the space in the forth line, so that in awk $1 $2 don't work.
>Ther may be also additional blanks in the file-Name ( Win... )

sed 's/\(.*\)   \(.*\)/\2       \1/' infile > outfile
             ^^^         ^^^^^^^
where those spaces are ^V<TAB>

man sed

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 06 Jan 2004 03:07:12 GMT  
 sed - how to change columns


% I just want to change to columns among an TAB:

You need to change the field separator and output field separator to
a tab:
 BEGIN { FS = OFS = "\t" }
 { print $2, $1 }

Because of quoting issues in the NT command-line, I suggest putting this
in a file and including it like so:

 awk -f flip.awk infile > outfile

--

Patrick TJ McPhee
East York  Canada



Mon, 12 Jan 2004 08:11:35 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. sed/awk - grabbing column/pos help!!

2. Changing Database-Bound ListBox Column Order

3. Changing list box columns at runtime

4. changing format in one list column

5. Changing EIP Column Sequence

6. Changing Column Titles in Browse box

7. How to change listbox column text at runtime??

8. Change database column length

9. change column title in a browse

10. Dynamically change report header and column header based on glo variable

11. Changing a list box columns for ea Tab

12. Changing EIP Handling in Column

 

 
Powered by phpBB® Forum Software