Help with varying data


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with varying data
# 15  
Old 02-14-2012
This prtal is not allowing me to paste the original data.PLease find attached teh sample data with which i am working with
# 16  
Old 02-15-2012
Hi, that file is in DOS format. It contains 3 records of 991 characters and 4 empty lines with one carriage return character. If I convert it to unix through
Code:
tr -d '\r' < infile.dos > infile

Then each line has 990 characters and 4 empty lines
When I run this:
Code:
awk '/^1000100/ {$0=sprintf("%s%0" w-length "s", $0,x)}1' w=1000 infile

10 zeroes are padded at the end of the 3 records..
If I do the same on the DOS file then 9 zeroes get written after the carriage return character and before the newline, so they get written at the beginning of the wrapped line on the terminal it happens to be displayed on....
# 17  
Old 02-15-2012
Hi Scrutnizer

Since i am new to unix can u let me know how you got to know tht the data file is in DOS format.

And also i will want to retain the the other data also

Source:
1000100............
3000300.........
34323...........
.
.
.

output required :
1000100............( padded with zeros and record size made to 1000)
3000300.........(original data length from source itself)
34323...........(original data length from source itself)
.
.
.
.
# 18  
Old 02-15-2012
Hi you can do this
Code:
if grep -q '^M' file; then
  echo "This is a DOS file"
fi

note: you cannot copy-paste this command. The ^M is one character, entered like this on the command line CTRL-V <ENTER>

Or you could use
use od -c to check if there are CR characters. Then you see \r \n combinations..
Code:
if od -c file | grep -q '\\r *\\n' ; then
  echo "This is a DOS file"
fi

This User Gave Thanks to Scrutinizer For This Post:
# 19  
Old 02-28-2012
Hey Scrutnizer thnks a lot the script works fine for me Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge lines with varying characters

Hi, I have a large set of data (firewall logs) that I'm trying to summarize. I've been able to write a script to consolidate the ports, now am looking to conslidate even further, based on IP. Source Destination Type Port 192.168.5.108 192.168.11.12 TCP 1, 2, 3, 4, 5, 15 192.168.5.109... (6 Replies)
Discussion started by: umang2382
6 Replies

2. Shell Programming and Scripting

How to separate data with varying amounts of underscores?

All, I've searched and haven't found a solution for my particular issue. I have a file with lines of data that contain varying amounts of underscores imbedded. But all the strings have a final underscore and an interface name: dmk_hcn_dalian2.XXXX.XXX.XX.COM_Se0/0/0... (4 Replies)
Discussion started by: turk22
4 Replies

3. Shell Programming and Scripting

Paste files of varying lengths

I have three files of varying lengths and different number of columns. How can I paste all three with all columns aligned? File1 ---- 123 File2 ---- 234 345 678 File3 ---- 456 789 Output should look like: 123 234 456 345 789 (6 Replies)
Discussion started by: Un1xNewb1e
6 Replies

4. Shell Programming and Scripting

Insert varying length spaces between words

Hey all, Fist post, so be kind... I have written an expect script which logs into a terminal and gathers several screens of information. Unfortunately the log file gives me all the special escape and control characters from the terminal. I am hoping to use a combination of shell scripting, sed,... (1 Reply)
Discussion started by: mpacer
1 Replies

5. Shell Programming and Scripting

How to check the varying file size

How to know a file is of fixed file or not over a span of time Actually my requirement is to check the size of the file in a specific directory for 60 seconds, and if it remains the same then I have to move to some other directory.Else I have to stop the execution. Request you to guide me in... (4 Replies)
Discussion started by: av_vinay
4 Replies

6. Shell Programming and Scripting

substitution of varying digits

I had a requirement in which in need to pan(*) out digits except the first six visible, followed by six *, and rest visible of a variable(input) ex: Input - 123456789012345 Output - 123456******345 ex: Input - 1234567890123456 Output - 123456******3456 so i tried something like... (12 Replies)
Discussion started by: mad_man12
12 Replies

7. Shell Programming and Scripting

extract string from varying delimiter line

Hi I have lines like this a=1, b=2, c=3, a=1, d=4, e=5, b=225, I need to extract the b=nnn... value. I dont know how many other entries will be before and after it in each line. Ive tried a basic line like awk '/b=/, $NF ~ /,/ ' myfile.txt but I think that it doesnt care which comma it... (5 Replies)
Discussion started by: rebelbuttmunch
5 Replies

8. Shell Programming and Scripting

Varying number of awk search strings

I've created an awk script that handles a varying number of search strings handed to it as command line parameters ($1 $2 etc). There may be 1, or 2 or 3 or more. A simplified version of the script is: awk -v TYP="$1 $2 $3 $4 $5 $6" ' BEGIN { CTYP = split (TYP,TYPP," ") } ... (2 Replies)
Discussion started by: CarlosNC
2 Replies

9. Shell Programming and Scripting

Parse apart strings of comma separated data with varying number of fields

I have a situation where I am reading a text file line-by-line. Those lines of data contain comma separated fields of data. However, each line can vary in the number of fields it can contain. What I need to do is parse apart each line and write each field of data found (left to right) into a file.... (7 Replies)
Discussion started by: 2reperry
7 Replies

10. Shell Programming and Scripting

deleting a varying amount of lines from a list of files

I did search the posts for info on this and while there were some in the ballpark, none addressed this specifically. (also I tried to post this once it said I was logged out, so hopefully I'm not sending a duplicate here). I have a set of files (250 +/-) where I need to delete the first "$x"... (4 Replies)
Discussion started by: benair
4 Replies
Login or Register to Ask a Question