Visit Our UNIX and Linux User Community


Remove 5th character from Field1 & Print


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove 5th character from Field1 & Print
# 1  
Old 12-11-2007
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
# 2  
Old 12-11-2007
Code:
sed -e "s/^\(....\).\(.*\)$/\1\2/g" file.txt


Last edited by vino; 12-11-2007 at 03:08 AM.. Reason: Typo
# 3  
Old 12-11-2007
Quote:
Originally Posted by vino
Code:
sed -e "s/^\(....\).\(.*\)$/\1\2" file.txt

Hi Vino,

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

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

# 4  
Old 12-11-2007
Quote:
Originally Posted by Raynon
Hi Vino,

Tried using your code but there's some error.
Can you help ?
My bad. I have corrected the sed statement.
# 5  
Old 12-11-2007
cat file | cut -c1-4,6-
# 6  
Old 12-13-2007
Hi prowla,

Thanks for your code.
It works just fine.
# 7  
Old 12-14-2007
Quote:
Originally Posted by Raynon
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
Code:
sed -n 's/^\(.\{4\}\). \(.*\)/\1 \2/p' file


Previous Thread | Next Thread
Test Your Knowledge in Computers #387
Difficulty: Medium
The Unix apropos utility locates commands using a neural network.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove alphabets/special characters/space in the 5th field of a tab delimited file?

Thank you for 4 looking this post. We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working. In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below. I... (12 Replies)
Discussion started by: Srithar
12 Replies

2. Shell Programming and Scripting

Grep the 5th and 6th position character of a word in a file

I am trying to find/grep the 5th and 6th position character (TX) of a word in a file. I tried to do grep "....TX" file The output gives me everything in the file with TX in it. I only need the output with the TX in the 5th and 6th position of the word. Any idea Example: test1 car... (5 Replies)
Discussion started by: e_mikey_2000
5 Replies

3. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

4. Shell Programming and Scripting

Script to search for a character in files in a Directory & remove it

Hi All, Am new to both Unix & this Forum - Need some help on a script that I am trying to write: In a Directory i have few text files which might or might not contain some text that I am trying to find. Once that text is found in any of the files, it needs to be removed from the file ... (6 Replies)
Discussion started by: rituparna_gupta
6 Replies

5. Shell Programming and Scripting

Remove 5th & 6th <td> from file

I have a page with a 6<td> structure. I need to strip the 5th and 6th <td></td> from the structure. The data in the 4th <td> varies, I can't get a pattern on it. So, I tried setting up a count of the td occurrence and then remove the 5th and 6th, but I'm not making any progress. Is there an easy,... (6 Replies)
Discussion started by: dba_frog
6 Replies

6. Shell Programming and Scripting

Remove 5th & 6th <td> from file

I have a page with a 6<td> structure. I need to strip the 5th and 6th <td></td> from the structure. The data in the 4th <td> varies, so I can't get a pattern on it. So, I tried setting up a count of the td occurrence and then remove the 5th and 6th, but I'm not making an progress. Is there an... (0 Replies)
Discussion started by: dba_frog
0 Replies

7. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

8. UNIX for Advanced & Expert Users

if 4th and 5th character of sting -ge 45 then add 1 to 3rd character

I want to know how to, given a string like W87151WR71C, if the 4th and 5th character (in this case 15) are greater than 45, then to add 1 to the 3rd character (in this case 7) and assign the revised string the variable name MODSTRING. Thanks in advance. This is ultimately to grab info from... (6 Replies)
Discussion started by: glev2005
6 Replies

9. Shell Programming and Scripting

csv file to array, match field1, replace in flat file field1 to field2

Hello, i am bit stuck with making script for automatic procedure. Case: Two files. One is flat file, other is csv file. csv file has two column/fields with comma delimited data. Here is what i need (explained way) CSV file: field1 | field2 "hello","byebye" "hello2","byebye2"... (23 Replies)
Discussion started by: frankie_konin
23 Replies

10. Shell Programming and Scripting

Can we use 'tr' command to print 5th column of output of 'ls -l'

Hi All, I know awk command can do it, but can we use tr command to print 5th column of out put 'ls -l' command???? Regards, Nidhi... (4 Replies)
Discussion started by: Nidhi2177
4 Replies

Featured Tech Videos