How to cut the particular string and increment the rows?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to cut the particular string and increment the rows?
# 1  
Old 11-07-2012
How to cut the particular string and increment the rows?

Hi am using unix aix


Quote:

I have a .txt files in a format .

vv |xcvb|
qa |cerd|
za |qwer|


Quote:
I Need output likes this
output=x
output=c
output=q
Code:
I have tried using awk but am getting only output = x ,its not incrementing next output
 
set -A var1 vv qa za
ct=0
i=3
while [ $ct -lt 3 ]
do
var1=`echo ${var1[$ct]}`
count=`awk ' NR==$i++ {print;exit}' ${.txt} | cut -c5 `
echo $count
let ct=ct+1
done

Can anyone help me how to increment NR
# 2  
Old 11-07-2012
Hi,

Try this one,

Code:
awk '{print "Count="substr($0,6,1);}'  input_file

perl -lne 'print "Count=",substr($_,5,1);' input_file

Cheers,
Ranga Smilie
# 3  
Old 11-07-2012
HI Its not working

Quote:
I have a file name called .txt
.txt files contents

|28|
vv |xcvb|
qa |cerd|
za |qwer|
Quote:
I need output like this printing x c q
output=x
output=c
output=q
# 4  
Old 11-07-2012
Code:
echo "|28|
vv |xcvb|
qa |cerd|
za |qwer|" | awk '/^[a-z]/ {print "output="substr($0,5,1);}'
output=x
output=c
output=q

# 5  
Old 11-07-2012
Try:
Code:
awk -F"|" '$1!=""{print "output = ", substr($2,1,1)}' .txt
output =  x
output =  c
output =  q

AND - please use proper code tags!
# 6  
Old 11-08-2012
Try like...
Code:
 awk -F"|" '{print "output="substr($2,1,1)}' test.txt

# 7  
Old 11-08-2012
This gives errada output
Code:
output=2
output=x
output=c
output=q

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and increment value in string of hex

I have a long string of hex (from ASN.1 data) where I need to find and change a particular hex value only and increment it. The hex pairs either side (84 and a7) of the value to increment will remain constant. i.e. "84 <length> <value_to_increment> a7" starting with 00. So end result: ... (11 Replies)
Discussion started by: securegooner
11 Replies

2. Shell Programming and Scripting

Find and increment at each occurence of string (loop)

I created script (sh shell) to generate vlc playlist based on some data files. All works fine so far except one string I do not know how to handle with. VLCSTART='<vlc:id>' VLCV=0 VLCEND='</vlc:id>' echo -e $'\n'$'\t'$'\t'$'\t'$'\t'\$VLCSTART$VLCV$VLCENDOutput file contains several occurences... (10 Replies)
Discussion started by: TiedCone
10 Replies

3. Shell Programming and Scripting

String increment in UNIX

Hi, I am able to increment numbers but unable to increment the charters in unix -AIX. Source : AAA BB CCC Increment Number : 5 OUTPUT: AAA BB CCC AAA BB CCD AAA BB CCE AAA BB CCF AAA BB CCG Thanks onesuri Please use CODE tags as required by the forum rules. I have made a wild... (5 Replies)
Discussion started by: onesuri
5 Replies

4. Shell Programming and Scripting

How to increment a string variable?

Hi All, I am new to this forum and a novice at shell script. I am trying to write a script to determine each of the NIC configured on a linux system and its speed and Duplex. I came up with the following piece of code: echo `ifconfig -a | grep eth > /home/a/nic.txt` i=`awk -F, '{print... (4 Replies)
Discussion started by: pravin883
4 Replies

5. Shell Programming and Scripting

How to copy or cut specific rows from appended file with some conditions

Hi I have one file which is containing about 5000 rows and 20 columns I will just explain about my requirement here briefly with sample file, I have attached also, please help....me.. 1 28.25 36.42 5 28.26 36.42 10 28.23 36.43 15 28.22 36.43 20 28.2 36.42 25... (6 Replies)
Discussion started by: nex_asp
6 Replies

6. Shell Programming and Scripting

Bash shell script: Str(007) to int(7),increment it(8) & convert back to string(008)

Hi, I have the following requirement. There will be following text/line in a file (eg: search-build.txt) PRODUCT_VERSION="V:01.002.007.Build1234" I need to update the incremental build number (eg here 007) every time I give a build through script. I am able to search the string and get... (4 Replies)
Discussion started by: drwatson_droid
4 Replies

7. UNIX for Dummies Questions & Answers

increment numbers in several parts of a string

I know how to do produce this: string01 string02 string03 several different ways. But how do I do produce this (without getting lost in recursion): string01morestring100yetmore10 string02morestring101yetmore20 string03morestring102yetmore30 ...... (2 Replies)
Discussion started by: uiop44
2 Replies

8. Shell Programming and Scripting

How reverse cut or read rows of lines

Hi, My records are like this BSC403_JAIN03|3153_TropicalFarm_LIMJM1-3_97| BSC403_JAIN03|3410_PantaiAceh_PCEHM1_4_97| BSC406_BMIN02|1433_JomHebohTV3_COW7M1_11_97| I want to extract the value before _97| This command BSC_ID=`echo $DATA | cut -f5 -d"_"` gives me _97|, 4, 11 and by... (16 Replies)
Discussion started by: doer
16 Replies

9. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

10. HP-UX

Cut rows

Hi, I have a requirement to search for two words and grep all the lines between them. For e.g. : $cat file.dat abc,To,number acd,To,cnz \* flexibile select *\ bcd,To,lla anz,From,kln app,From,lpz I need to get all the lines between the lines cantaining word 'acd' and 'anz'. the... (2 Replies)
Discussion started by: obedkhan
2 Replies
Login or Register to Ask a Question