Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Try -F '[|:]'. That removes both pipes and semi colons. – lgarzo Jan 27 '13 at 16:20
up vote 2 down vote accepted

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

awk 'BEGIN{FS="|"} $1 == "AUGUSTYN" { print NR " " $1 " " $2 " " $3}'
share|improve this answer
+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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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