Sponsored Content
Top Forums Shell Programming and Scripting Cut output to same byte position Post 302097257 by ghostdog74 on Wednesday 22nd of November 2006 09:51:06 PM
Old 11-22-2006
If you have Python, an alternative
Sample input:
-------------------
111333 444TTTLKOP
122333 444DDDLKOP
422333 4445DDLTlR


Code:
#!/usr/bin/python
start1,end1 = 3,6 #position 4-6
start2,end2 = 14,17 #position 15-17
for lines in open("test.txt"):
        lines = list(lines.strip())
        lines[start1:end1] = " " * (end1 - start1) #sub space at positoin 4-5
        lines[start2:end2] = " " * (end2 - start2)
        print ''.join(lines)

output:
Code:
111     444TTT   P
122     444DDD   P
422     4445DD   R

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

byte count and cut command

1. Is there a way to count the number of bytes of a variable? example: abc@yahoo.com is 13 bytes 2. Cut command only allows one byte for delimiter example: cut -f1 -d'.' delimited by period. Is there a way to have two or more characters in the delimiter field? thanks in adavance. :) (4 Replies)
Discussion started by: hemangjani
4 Replies

2. Shell Programming and Scripting

Cut position as a variable

Hi All, I wish to cut an input by using the below command but i would want to have the cut position as a variable. For eg, the position number is 11 now and i wish that this number is being assigned to a variable before putting into the cut function. Can this be done ? Can any expert help?... (1 Reply)
Discussion started by: Raynon
1 Replies

3. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

4. Shell Programming and Scripting

Remove a byte(Last byte from the last line)

Hi All Can anyone please suggest me how to remove the last byte from a falt file .This is from the last line's last BYTE. Please suggest me something. Thank's and regards Vinay (1 Reply)
Discussion started by: vinayrao
1 Replies

5. Shell Programming and Scripting

Perl- Output file is always 0 byte

Hi all, I am new to perl programming. However i have a script that connects to the database and spools that into an output file. Strange thing is that sometimes this script works and sometimes the ouput spool file is always 0 byte. I have verified the sql query and the query always returns... (5 Replies)
Discussion started by: amit1_x
5 Replies

6. Shell Programming and Scripting

Cut multiple data based on character position

How to extract multiple data based on character position. I need to fetch from 7-9 and 22-26 and there is no delimiter for 22-26 since it is part of the column. The file may have more than 1000 character long.I managed to pull any one but not both for example test data 12345 zxc vbnmlk... (1 Reply)
Discussion started by: zooby
1 Replies

7. Shell Programming and Scripting

How to cut line from certain position?

Hi Gurus, I want to cut my file from 27th charactor to the end of line. can anybody give some unix command to do this. Thanks in advance (3 Replies)
Discussion started by: ken6503
3 Replies

8. UNIX for Beginners Questions & Answers

Cut two individual position and summ

Hi All, I am having a huge file file. I need to cut the below column and do the below calculation I did the below command and able to do on full databased no on the individual based any help on doing each row by row cut -c 52-56 myfile | awk '{total = total + $1}END{print total}'... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

9. UNIX for Beginners Questions & Answers

Print byte position of extended ascii character

Hello, I am on AIX. When I encounter extended ascii characters and special characters on a file I need to print.. Byte position, actual character and line number. Is there a simple command that can give me the above result ? Thanks in advance (38 Replies)
Discussion started by: rosebud123
38 Replies

10. Shell Programming and Scripting

Cut command with dynamic passing of delimiter and position values

Hi All, We have a requirement of picking nth position value by using cut command. value would be delimited by any symbols. We have to pass delimited value and postition to get the value in a string. ex. echo "A,B,C,D,E" |cut -d "," -f3 echo "A|B|C|D|E"|cut -d "|" -f2 Kindly frame the... (5 Replies)
Discussion started by: KK230689
5 Replies
UNIFDEF(1)						      General Commands Manual							UNIFDEF(1)

NAME
unifdef - remove ifdef'ed lines SYNOPSIS
unifdef [ -t -l -c -Dsym -Usym -idsym -iusym ] ... [ file ] DESCRIPTION
Unifdef is useful for removing ifdef'ed lines from a file while otherwise leaving the file alone. Unifdef is like a stripped-down C pre- processor: it is smart enough to deal with the nested ifdefs, comments, single and double quotes of C syntax so that it can do its job, but it doesn't do any including or interpretation of macros. Neither does it strip out comments, though it recognizes and ignores them. You specify which symbols you want defined -Dsym or undefined -Usym and the lines inside those ifdefs will be copied to the output or removed as appropriate. The ifdef, ifndef, else, and endif lines associated with sym will also be removed. Ifdefs involving symbols you don't specify are untouched and copied out along with their associated ifdef, else, and endif lines. If an ifdef X occurs nested inside another ifdef X, then the inside ifdef is treated as if it were an unrecognized symbol. If the same symbol appears in more than one argument, only the first occurrence is significant. The -l option causes unifdef to replace removed lines with blank lines instead of deleting them. If you use ifdefs to delimit non-C lines, such as comments or code which is under construction, then you must tell unifdef which symbols are used for that purpose so that it won't try to parse for quotes and comments in those ifdef'ed lines. You specify that you want the lines inside certain ifdefs to be ignored but copied out with -idsym and -iusym similar to -Dsym and -Usym above. If you want to use unifdef for plain text (not C code), use the -t option. This makes unifdef refrain from attempting to recognize com- ments and single and double quotes. Unifdef copies its output to stdout and will take its input from stdin if no file argument is given. If the -c argument is specified, then the operation of unifdef is complemented, i.e. the lines that would have been removed or blanked are retained and vice versa. SEE ALSO
diff(1) DIAGNOSTICS
Premature EOF, inappropriate else or endif. Exit status is 0 if output is exact copy of input, 1 if not, 2 if trouble. BUGS
Does not know how to deal with cpp consructs such as #if defined(X) || defined(Y) AUTHOR
Dave Yost 4.3 Berkeley Distribution April 29, 1985 UNIFDEF(1)
All times are GMT -4. The time now is 09:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy