Remove 5th character from Field1 & Print

Hi ,

I need to remove the 5th character of column1 and print the rest.
Can anybody give some advice?

Input:

0001c xx
0001r gg jj
0002y vv
0002p kk
0003q gg ll
0003v tt
0003t gg pp kk

Output:

0001 xx
0001 gg jj
0002 vv
0002 kk
0003 gg ll
0003 tt
0003 gg pp kk

sed -e "s/^\(....\).\(.*\)$/\1\2/g" file.txt

Hi Vino,

Tried using your code but there's some error.
Can you help ?

$ sed -e "s/^\(....\).\(.*\)$/\1\2" myfile
Variable syntax

My bad. I have corrected the sed statement.

cat file | cut -c1-4,6-

Hi prowla,

Thanks for your code.
It works just fine.

sed -n 's/^\(.\{4\}\). \(.*\)/\1 \2/p' file

hi,
how can i post my new doubt?i.e.how can i post a new query?i am not getting any option related to this..please help asap

any explanation of thoese sed commands..in this context..I mean I know basics of sed.

thanks in advance

The base of the all is to match the first four characters in a line (the four dots) and put tem into a variable (the surrounding escaped brackets), then match the 6th and all following characters and put them into a variable too - in other words, match the complete line except the fifth character. I have marked the first, second and third part of the regexp with 1, 2 and 3 for you. In the output you skip part 2:

sed 's/^\(....\).\(.*\)$/\1\2/'
        111111112333333

The other sed-statement is just a variation on that. You can "multiply" regular expressions: The asterisk is such a "multiplier", it will create a copy of the previous regular expression as often as it is needed to match. The construction with the curly brackets is less vague: you can control the exact number of repetitions or even a range of repetitions. The following regexp parts are examples of this:

/..../    /.\{4\}/  -> four times the preceding "."

/.*/                -> matches 0 or more instances of "."
/.\{4,5\}/          -> matches 4 or 5 instances of "."

bakunin