removing a delimiter at the start of row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing a delimiter at the start of row
# 1  
Old 10-24-2007
removing a delimiter at the start of row

I Have this code



while [ ${iCount1} -le ${reccount} ]

do

column1=":`cat /home/test_inter.txt|head -${iCount1}|tail -1|cut -d "," -f2`"

columnA=$columnA$column1

iCount1=`expr ${iCount1} + 1`

done

echo $columnA





The output of this code is coming as

:1:2:2:3:3:4



A colon(Smilie at the beginning of each row I am using this colon as a field delimiter. But I don't want it at the beginning of each row.



Any help regarding this?
# 2  
Old 10-24-2007
Not a very efficient solution:
Code:
echo ":1:2:2:3:3:4" |  cut -c 2-

Get everything from second character onwards
# 3  
Old 10-24-2007
The reason is, that you preceed EACH field with a colon in the "column1=...." line. Since you do this in a loop anyways (i'm pretty sure you could achieve this more easily, but that only as a aside) start without the colon and only add the colon from field 2 onwards. Oh, by the way: backticks are OUT and "expr" is unnecessary in ksh:

Code:
column1="$(cat /home/test_inter.txt|head -1|tail -1|cut -d "," -f2)"
iCount=2
while [ ${iCount1} -le ${reccount} ] ; do

     column1="${column1}:$( cat /home/test_inter.txt |\
                            head -${iCount1} |\
                            tail -1 |\
                            cut -d "," -f2 \
                          )"


     (( iCount1++ ))

done

echo $column1

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split files based on row delimiter count

I have a huge file (around 4-5 GB containing 20 million rows) which has text like: <EOFD>11<EOFD>22<EORD>2<EOFD>2222<EOFD>3333<EORD>3<EOFD>44<EOFD>55<EORD>66<EOFD>888<EOFD>9999<EORD> Actually above is an extracted file from a Sql Server with each field delimited by <EOFD> and each row ends... (8 Replies)
Discussion started by: amvip
8 Replies

2. Shell Programming and Scripting

Count delimiter(~|*) each row in a file and return 1 or 0

Hi I want to check delimiter in file. Delimiter in my file is ~|* sample of file : ABC~|*edgf~|*T1J333~|*20121130 ABC~|*sdaf~|*T1J333~|*20121130 ABC~|*fsdg~|*T1J333~|*20121130 ABC~|*dfsg~|*T1J333~|*20121130 in this i want to count number delimiter occur is 4 in each row if count is... (21 Replies)
Discussion started by: MOHANP12
21 Replies

3. Shell Programming and Scripting

Split a file by start and end row.

I have a file which looks something as following, I would like to split to several files, The start and end of each file is 'FILE' and end with 'ASCII... ' . At the same time for each file in the first column add 100 and also second column add 100 the rest of the column as it is , see example of... (2 Replies)
Discussion started by: tk2000
2 Replies

4. Shell Programming and Scripting

Removing duplicate lines on first column based with pipe delimiter

Hi, I have tried to remove dublicate lines based on first column with pipe delimiter . but i ma not able to get some uniqu lines Command : sort -t'|' -nuk1 file.txt Input : 38376KZ|09/25/15|1.057 38376KZ|09/25/15|1.057 02006YB|09/25/15|0.859 12593PS|09/25/15|2.803... (2 Replies)
Discussion started by: parithi06
2 Replies

5. Shell Programming and Scripting

Convert row to columns start from nth column

Dear All, We have input like this: 161 57 1378 176 1392 262 1444 441 1548 538 1611 670 1684 241 57 1378 208 1393 269 1447 444 1549 538 1610 677 1700 321 ... (4 Replies)
Discussion started by: attila
4 Replies

6. Shell Programming and Scripting

Removing un-necessary start string

i have input in below form part=gfjhwhedaqh=ghdgwg^*^(G== i want to remove the starting "part=" and retain the remaining. please suggest (4 Replies)
Discussion started by: skyineyes
4 Replies

7. Shell Programming and Scripting

Column to row with delimiter

Hi, i have data in a file f1.txt a b c d and i want to print the above column values in single line with a delimiter, say ',' The output should look like: a,b,c,d I could find rows to columns help online but not vice versa Thanks, -srinivas yelamanchili (4 Replies)
Discussion started by: ysrini
4 Replies

8. Shell Programming and Scripting

Counting number of records with string row delimiter

HI, i have a file like this t.txt f1|_f2|_ f1|_f2|_ f1|_f2|_ as if col delimiter is |_ and row delimiter |_\n trying to count number of records using awk $ awk 'BEGIN{FS="|_" ; RS="~~\n"} {n++}END{print n} ' t.txt 7 wondering how can i count this to 3 ? thx (9 Replies)
Discussion started by: aksforum
9 Replies

9. Shell Programming and Scripting

removing files with certain number in the first row

Hello! I have 32000 files in a directory and want to remove those with first row beging with 0.00; file names are in numbers from 1 through 32000; I have coded the following but it gives me error: while ( i <= 32000 ) if (head -1 $i ==0.00) rm $i end Well, i am sure even if this... (14 Replies)
Discussion started by: nxp
14 Replies

10. Shell Programming and Scripting

help with sed to add delimiter and new field to each row

I have a file with millions of rows that I need to add a delimiter and a new field with a zero to the end of each row. (its too big to open and do a find and replace regex) I'm looking for the next line '\n' and need to replace it with a Unit Separator (hex \037) 0 \n. I've tried the... (2 Replies)
Discussion started by: kmac
2 Replies
Login or Register to Ask a Question