I would like get this string line


without | and :

I tried something like that:

cat baza|grep "AUGUSTYN" -n|awk -F '|' '{print $1,$2,$3,$4}'`

(baza is my file with text, and AUGUSTYN is the name of person)

Result of this command is:

1:AUGUSTYN Stanisław 3589238 

As you see there still this pipe :( And I would like to get this:

1 AUGUSTYN Stanisław 3589238

I take text from this base file:


Getting strings without | and : would be great but I will have to get the number of line where this text is stored. So I had to use grep. If you can find any other more obvious solution for this too It would be mega great.

How can I archieve it? I started it learning an hour ago this awk. Please help.

  • 2
    Try -F '[|:]'. That removes both pipes and semi colons. – lgarzo Jan 27 '13 at 16:20

grep is not necessary, you can do this with awk alone:

awk 'BEGIN{FS="|"} $1 == "AUGUSTYN" { print NR " " $1 " " $2 " " $3}'
  • 4
    +1. You can take advantage of awk's output field separator (default a space) like this: awk -F\| '{$1=$1; print NR, $0}' -- the $1=$1 part forces awk to rewrite the input line using the output field separator. This method allows you to avoid hardcoding the number of fields. – glenn jackman Jan 27 '13 at 18:00

How about adding | sed "s/:/ /" at the end of your command? so it's like this

cat baza|grep "AUGUSTYN" -n|awk -F '|' '{print $1,$2,$3,$4}' | sed "s/:/ /"

Unless I'm misunderstanding you and you want to do that in 1 command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.