Record length check fails due to '\' character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Record length check fails due to '\' character
# 8  
Old 03-27-2013
Without actually seeing the script I can only guess, but I think you lose your one byte somewhere when reading the file line by line.
Also I'd be careful with the -c option of wc. It counts bytes, not characters. Multibyte characters may cause your script to fail:
Code:
$ echo -ne 'äbc' |wc -c
4
$ echo -ne 'äbc' |wc -m
3

# 9  
Old 03-27-2013
It would help if you could post more details.

wc -c is not ignoring or missing the \ backslash character.
wc -c just counts the number of bytes that it sees.

If your byte count is too small, it's because some sequence such as \n or \t is getting changed to one byte BEFORE wc -c sees it. Here is an example showing one way this can happen. There are doubtless other ways:
Code:
$ echo "\t"            # First \, then t, then newline
\t
$ echo "\t" | wc -c
3

Code:
$ echo -e "\t"         # TAB character, then newline

$ echo -e "\t" | wc -c
2

# 10  
Old 03-27-2013
Most likely what you are seeing as \e (or backslash whatever) when you view the file is not a backslash at all - it's your shell command or editor displaying an unprintable character (which is indeed 1 byte long).

Try using od on the file to see what the actual character is.

Last edited by CarloM; 03-27-2013 at 06:47 PM..
# 11  
Old 03-27-2013
Amrutha24, if you would like prompt and accurate assistance, do yourself a favor and post the exact commands that you are using. It is ridiculous that this thread has grown to two pages, that you have posted in it multiple times, and that you still have yet to share your code.

If you're using read, you're using it incorrectly. However, due to your inadequate posts, that is only a guess.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh fails due to argument position.

I have a constraint to follow organization policy. So i do not have much liberty. ssh -i /opt/nonprod user1@hostone -t bash works while ssh -i /opt/nonprod -t bash user1@hostone fails How can I get this to work when I am enforced to put -t bash before the user@hostname ? Will share debug... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies

3. Shell Programming and Scripting

Check for length which exceeds specified length in a line

Hi, I have a issue, I need to loop through a comma delimited file and check for the length which exceeds specified length , if Yes truncate the string. But my problem is , I do not have to check for all the fields and the field lenght is not same for all the fields. For ex: Say my line... (9 Replies)
Discussion started by: rashmisb
9 Replies

4. OS X (Apple)

Compiling fails due to space in path to home folder

I seem to have issues compiling software and I think I've narrowed it down to something having to do with having a space in the path name to my Home folder (which contains "Macintosh HD"). The reason I think this is shown here: $ echo $HOME /Volumes/Macintosh HD/Users/Tom $ cd $HOME -sh:... (7 Replies)
Discussion started by: tdgrant1
7 Replies

5. Shell Programming and Scripting

Add character based on record length

All, I can't seem to find exactly what I'm looking for, and haven't had any luck patching things together. I need to look through a file, and if the record length is not 874, then add 'E' in position 778. Your help is greatly appreciated. (4 Replies)
Discussion started by: CutNPaste
4 Replies

6. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

7. Shell Programming and Scripting

Check length of record

Hi, I have a problem, please help me, I have a flat file like this: P00000000088888888999999999 0000999903 000000000000000000 P00000000077777777000000000 0000999903 000000000000000000 P00000000044444444333333333 0000999903 00000000000000000079875 P00000000066666666111111111 0000999903 ... (5 Replies)
Discussion started by: DebianJ
5 Replies

8. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

9. Shell Programming and Scripting

Using Awk script to check length of a character

Hi All , I am trying to build a script using awk that checks columns of the înput file and displays message if the column length exceeds 35 char. i have tried the below code but it does not work properly (2 Replies)
Discussion started by: amit1_x
2 Replies
Login or Register to Ask a Question