read string, check string length and cut


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read string, check string length and cut
# 8  
Old 03-21-2007
Well, I tried out the awk - and thought it might be a little easier to read (just to understand it better) if you try it like this:

1) create "search.awk" and inside, put this:
Code:
BEGIN { lengths="10,8,21,5,5,5"
        FS = OFS = ","
        split(lengths,size,FS)
      }
      { n = 0
        while ( ++n <= NF ) $n = substr($n,1,size[n])
        print
      }

2) save and then run like this:
"awk -f search.awk csv.file"

3) output is:
1,Test Nam,"This is a test and i,,,1234


...so the theory works. Except that it includes the " as a char.

Hope this is enough to set your mind off on the right track!
# 9  
Old 03-21-2007
Quote:
Originally Posted by ozzy80
The awk is not working... says syntaz error!!!

Are you running on Solaris?

If so, use nawk or /usr/xpg4/bin/awk.

# 10  
Old 03-21-2007
Thnx guyz for all the help!!! will come back soon Smilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to count matched string then check again from last read position

Hi all, I am currently trying to figure out how can i capture a particular string from a log file, then search again but from the last line it read before onward. Basically let's say that the check runs every 5 mins via cron, counting the number of matched strings "Cannot assign requested... (5 Replies)
Discussion started by: nms
5 Replies

2. Shell Programming and Scripting

How to read file, and replace certain string with another string?

Hi all, the value in the following file is just an example. It could be a different value/network addresses. Here is my example of initial output in a file name net.txt Initial Output, net.txt The goal is to produce the following format which is to convert from CIDR to Netmask... (6 Replies)
Discussion started by: type8code0
6 Replies

3. UNIX for Dummies Questions & Answers

I need a Script to read Log string and check date at the same time

I need to check 1 log file, which is logging: 2014-08-18T09:10:39+02:00 user: XXXXX START FEATURE 2014-08-18T09:10:39+02:00 user: XXXXX FINISH FEATURE I first need to check that the START FEATURE starts and finish on the same time/date for the same user, which is different each time START... (2 Replies)
Discussion started by: TheBest43
2 Replies

4. Shell Programming and Scripting

Check file for string existence before appending it with string

I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
Discussion started by: sahil_shine
2 Replies

5. Shell Programming and Scripting

Read File and check records for length

I need a script that will run in unix to: 1) Read and input file with 1 column that contains for ex: 0123456789 1234567890 ...etc 2) Checks the first column if it is: a. Numeric from 0 - 9 b. if it is not less... (4 Replies)
Discussion started by: mrn6430
4 Replies

6. Shell Programming and Scripting

how to cut a string from a string

now I have a string .a/b/c/done I want to get "done" from it. That is the result should be "done" sorry for my language before. Thanks in advance (5 Replies)
Discussion started by: Henryyy
5 Replies

7. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

8. Shell Programming and Scripting

Read string from a file,plz help me to check

#!/usr/bin/ksh exec 0<property while read newReceiveDir do if then sed -e 's//home/joshua/bodi/data/receive/{$newReceiveDir:25}/g/' mp_validate.sh >| mp_validate.sh elif then sed -e 's//home/joshua/bodi/data/temp/{$newReceiveDir:22}/g/' mp_validate.sh >| mp_validate.sh ... (1 Reply)
Discussion started by: joshuaduan
1 Replies

9. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies
Login or Register to Ask a Question