How can I get rid of the ` character from input file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I get rid of the ` character from input file?
# 1  
Old 08-07-2008
How can I get rid of the ` character from input file?

A sed command works most of the time however it fails sometimes.

I put each line (record) I read of a file through the following command
data=$(cat file | sed 's/[^a-zA-Z0-9+_:-]//g' | sed 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' )

When I run the script I get a message that states that there is an invalid format character.

The list of invalid chracters I am getting is as below, is there a way to solve this issue?. How can I get rid of the ` character from the input data?

`w'
`m'
`k'
``'
`;'
`O'
`m'
`H'
`^'
` '
`:'
`v'
`S'
`k'
`j'
`)'
`!'
`['
`m'
`@'
`T'
# 2  
Old 08-07-2008
Tools Does the following work?

Since the character is the first in each line...

Code:
cat file | cut -c2-

# 3  
Old 08-07-2008
Its not the first character

I am afraid its not the first character, I have specified the message that is displayed on the screen when I run my script which is of the format ./records.sh invalid chracters....etc
# 4  
Old 08-07-2008
Post input data

Can you provide a sample of the input file
# 5  
Old 08-07-2008

To answer the question in the subject line:

Code:
tr -d '`' < FILE

Quote:
Originally Posted by gugs
A sed command works most of the time however it fails sometimes.

Under what conditions does it fail?
Quote:
I put each line (record) I read of a file through the following command

I hope you don't really run the entire file through two instances of sed (not to mention cat) for every line in the file.
Quote:
data=$(cat file | sed 's/[^a-zA-Z0-9+_:-]//g' | sed 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' )

You are using three external commands where you only need one:
Code:
data=$( sed -e 's/[^a-zA-Z0-9+_:-]//g' -e 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' file )

Quote:
When I run the script I get a message that states that there is an invalid format character.

Please post the exact message you get. (Cut and paste it, don't retype it.)
Quote:
The list of invalid chracters I am getting is as below, is there a way to solve this issue?. How can I get rid of the ` character from the input data?

Why do you think the problem is the ` character?

The invalid characters are those between the quotes.
Quote:

`w'
`m'
[snip]
`@'
`T'
# 6  
Old 08-08-2008
Sample data

cfajohnson, unfortunately I cannot post a copy of the data because I am not allowed, confidential info. The only reason I know that these chars are causing a problem is because I get an on line message: ./counter.sh line 5: printf: `w: invalid format and this is repeated for characters that I have mentioned in my initial posting. The contents of counter.sh is:

counter=1
while read line
do
# Test the file
printf "$line" > temp$counter
pref=$(sed <$temp$counter -e 's/[^a-zA-Z0-9+_:-]//g' -e 's|.*ex:Msg\(.*\)ex:Msg.*|\1|')
printf"
let counter=counter+1
done < temp01

Also you mention that I could use only one command instead of three for extarcting the data. Could you please specify? I am new to scripting so any help would be greatly appreciated.

Code:
data=$( sed -e 's/[^a-zA-Z0-9+_:-]//g' -e 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' file )
# 7  
Old 08-08-2008
Quote:
Originally Posted by gugs
cfajohnson, unfortunately I cannot post a copy of the data because I am not allowed, confidential info. The only reason I know that these chars are causing a problem is because I get an on line message: ./counter.sh line 5: printf: `w: invalid format

As the message says, you are using an invalid format character with printf.

The syntaxt for printf is:
Code:
printf FORMAT_STRING ARG ...

What you need is:
Code:
printf "%s\n" "$line"

Quote:
and this is repeated for characters that I have mentioned in my initial posting. The contents of counter.sh is:

Please put code inside code tags.
Quote:
Code:
 
counter=1
while read line
do
  # Test the file 
  printf "$line" > temp$counter
  pref=$(sed <$temp$counter -e 's/[^a-zA-Z0-9+_:-]//g' -e 's|.*ex:Msg\(.*\)ex:Msg.*|\1|')
printf"


Don't use sed for every line in a file; it will be extremely slow.

Use sed on the entire file and work on its output.
Quote:
let counter=counter+1

Use the standard form for arithmetic:
Code:
counter=$(( $counter + 1 ))

Quote:
Code:
 
done < temp01

Also you mention that I could use only one command instead of three for extarcting the data. Could you please specify? I am new to scripting so any help would be greatly appreciated.

Code:
data=$( sed -e 's/[^a-zA-Z0-9+_:-]//g' -e 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' file )

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace character string in txt file using input file(S)

Hi I have a large txt file on my AIX server and I need to replace some text using two other files. So filename1 has about 500 lines similar to: txtcode SYStem100 I have the string I want to change in string2 and the new stringname in string3. Does anyone know a way of doing this? I have... (1 Reply)
Discussion started by: Grueben
1 Replies

2. Shell Programming and Scripting

Why menu won't allow 2 character input?

I’m trying to write a script for users to easily check folder size. The idea is to have a menu that starts at the top directory and then drills down to lower directories. Selections 1-9 work fine. The issue I’m having is any 2 digit menu selections (10+) doesn’t work and it returns the error... (3 Replies)
Discussion started by: MarkCyc
3 Replies

3. Shell Programming and Scripting

URGENT!!!move character x of input string to some position

i have this prob I have some records in a file1 like this 1001 sajal singh tampa 1002 .... so on i have a pattern file which is like this 1,4 4,13 14,15 i have to read the first pair 1,4 and extract that from the first record so the pattern is 1001 now i have to scramble 1001... (1 Reply)
Discussion started by: spankincubus
1 Replies

4. Solaris

solaris 10 login. I can not input any character

well I am using vmware to install solaris 10. everything went smooth( I installed it like 1000 times already and i get the same problem with login.) I can type my username without any problem but when i go to type my password. it does not take any character. i cant see anything. It is very... (5 Replies)
Discussion started by: unhuman
5 Replies

5. Shell Programming and Scripting

get rid of "^" character in a .txt file

I have a file that I ran the dos2unix utility on, it cleans up pretty well, but I noticed an occasional ^M leftover, (actual characters) these may or may not be strays from my original dos file. Either way, I want to get rid of the ^ and any character that may follow. ^M ^C or whatever. How do I... (6 Replies)
Discussion started by: ajp7701
6 Replies

6. Shell Programming and Scripting

Get rid of the 7th character of each line if this is a space

I have a text file like this ... B 16 1.340E+05 A 18 3.083E+02 Wu123 1.365E+02 ... I would like to get rid of the 7th character of each line if this is a space character. Thank you, Sarah (5 Replies)
Discussion started by: f_o_555
5 Replies

7. Shell Programming and Scripting

unwanted control character in the input

Hi Shell Scripting Experts, I have a shell script running daily on a remote machine through ssh. To avoid the trouble of restarting the script when ssh disconnects, I use screen (a unix tool) and run the script within a screen session. What this script does is to ask the user to input y or n... (2 Replies)
Discussion started by: jeff_cen
2 Replies

8. Shell Programming and Scripting

how to get rid of ^M in the file

Hi I have a file wich contains ^M characters, looks like these are from DOS, Is there a way to get rid of them? Thanks -A (3 Replies)
Discussion started by: aoussenko
3 Replies

9. Shell Programming and Scripting

validating a input file for numeric and character

i have a input file like this 001|rahim|bajaj|20090102 while reading the file i need to check whether the first column is a number second column is a name is there any methodology to check for the same thanks in advance (2 Replies)
Discussion started by: trichyselva
2 Replies

10. UNIX for Advanced & Expert Users

Get rid of junk character in a file

I have a file with one of the following lines, when opened with vi 33560010686GPT£120600GBPGBP10082007DS In the above line, I want to get rid of the junk character before the £ (pound sysmbol). When I tried copying £ from windows and copy in unix vi, it prints as £ and I tried pattern replace... (2 Replies)
Discussion started by: nskworld
2 Replies
Login or Register to Ask a Question