Cut and append the text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut and append the text
# 1  
Old 08-18-2010
Error Cut and append the text

I have a text like this ... i need append the text whihc is after 'csb' into the end of the line


input
-----
Code:
sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl
sdir;csp oc_lib-0.10.4;bdir;cbpdob ---enable-useosstl

output
Code:
sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl os_lib-0.5.24
sdir;csp oc_lib-0.10.4;bdir;cbpdob ---enable-useosstl oc_lib-0.10.4

iam using a command below
but iam not sure how to pass the output to sed
Code:
cut -d " " -f2 pkglist_bkp |  cut -d ";" -f1 | sed 's/$//' pkglist_bkp


Last edited by zaxxon; 08-18-2010 at 06:13 AM.. Reason: repairing code tag ;) user did already - was still editing, sorry
# 2  
Old 08-18-2010
Hi


Code:
#awk -F "[ ;]" '{print $0,$3;}' file
sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl os_lib-0.5.24
sdir;csp oc_lib-0.10.4;bdir;cbpdob ---enable-useosstl oc_lib-0.10.4
#

Guru.
# 3  
Old 08-18-2010
Code:
awk 'BEGIN{FS=";"} {print $0,$2;}' file | sed -e 's/ csp / /g'

This User Gave Thanks to rajamadhavan For This Post:
# 4  
Old 08-18-2010
in single run:
Code:
awk -F\; '$2~"^csp"{split($2,f," ");print $0,f[2]}' pkglist_bkp

# 5  
Old 08-18-2010
Thanks a lot for all

---------- Post updated at 03:04 PM ---------- Previous update was at 03:02 PM ----------

Code:
awk -F\; '$2~"^csp"{split($2,f," ");print $0,f[2]}' pkglist_bkp

Iam getting error for this

Code:
awk -F\; '$2~"^csp"{split($2,f," ");print $0,f[2]}' pkglist_bkp
awk: syntax error near line 1
awk: bailing out near line 1

# 6  
Old 08-18-2010
Code:
# a=[sc];sed "s/\(.*\)\(o$a_lib.*\)\(;.*;.*\)/\1\2\3 \2/" infile
sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl os_lib-0.5.24
sdir;csp oc_lib-0.10.4;bdir;cbpdob ---enable-useosstl oc_lib-0.10.4

# 7  
Old 08-18-2010
Quote:
Originally Posted by girija
Thanks a lot for all

---------- Post updated at 03:04 PM ---------- Previous update was at 03:02 PM ----------

Code:
awk -F\; '$2~"^csp"{split($2,f," ");print $0,f[2]}' pkglist_bkp

Iam getting error for this

Code:
awk -F\; '$2~"^csp"{split($2,f," ");print $0,f[2]}' pkglist_bkp
awk: syntax error near line 1
awk: bailing out near line 1

Try:
Code:
awk -F";" '$2~"^csp"{split($2,f," ");print $0,f[2]}' pkglist_bkp

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to preserve the same text and modify the same text to append?

Hi, I have an issue modifying a file. Below is the content of the file. File name - a.txt SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*12 + 3), LISTAGG(DOB) from T_CONCAT ; SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*100 + 3), from... (1 Reply)
Discussion started by: Mannu2525
1 Replies

2. Shell Programming and Scripting

How to append a text file?

i have to append a text file grep for a word, if found, put comment in starting of the line. here is an example cat test.sh bin/ksh Hello World Test Message :wq! search for "bin" word in test.sh file if found comment it out at starting of the line: Output as follows: #bin/ksh... (5 Replies)
Discussion started by: raghur77
5 Replies

3. Shell Programming and Scripting

Help Needed! - Cut characters after a text string and append to end of filename

Hi all.. I have several unique files that contain one thing in common, and that is acct#. For all files in the directory, I want to append the 10 characters following the word "ACCOUNT:" to the end of the filename. for example: I have file 111_123 that contains ACCOUNT:ABC1234567 The file... (5 Replies)
Discussion started by: cinderella1
5 Replies

4. Shell Programming and Scripting

Use sed to append text to filenames if text not already present

I have some html with hrefs that contain local links to pdf filenames. These filenames should have standardised names, i.e. there should be a label prior to the ".pdf" filename suffix. There can be many of these links on a single line of text and some may already have the label. For example ... (13 Replies)
Discussion started by: adb
13 Replies

5. UNIX for Dummies Questions & Answers

Append text to files with a same pattern

Hi Folks, I wanted to know if i can use RegEx in a for-loop of a shell script. Here's a scenario, I have a set of files say x1, x2, x3..x9 in a directory(obviously with files other than this pattern). I want to append a line of text to all files that follow pattern x. Can someone help me out? I... (4 Replies)
Discussion started by: prithvirao17
4 Replies

6. Shell Programming and Scripting

Append text error?

Sup guys, today I tried to append a string from my text by asking the user to input and change the specific text they wanna append. The problem is that, the code looks logically correct, but when I run it there's an error somewhere. Can anyone identify for me? echo "Search data" read... (4 Replies)
Discussion started by: aLHaNz
4 Replies

7. Shell Programming and Scripting

append each line with text

hi, I've a file with some text in it, i need to append few strings in the beginning and end of each row. --in file richie matt .. --out file hi, 'richie' is here hi, 'matt' is here ... I tried with awk command, but it fails because of ' Thanks (2 Replies)
Discussion started by: dvah
2 Replies

8. UNIX for Advanced & Expert Users

cut and append the file based on id

Hi, I have a file which have set of rows and has to create separate files based on the id. Eg: 001_AHaris020 001_ATony030 002_AChris090 002_ASmit060 003_AJhon001 Output: I want three files like 001_A.txt, 002_A.txt and 003_A.txt. 001_A.txt should have ... (1 Reply)
Discussion started by: techmoris
1 Replies

9. Shell Programming and Scripting

how to append text into a file.

I have a command stream that will parse down an ftp DIR listing of a remote directory and return the name of the newest file that I am interested in. The command is sed -e '/^d/d' sppay.listing |sed -n -e '/SPPAY/p'|sort -r -k 43M,45 -k 47,48 -k 50,54|sed -n -e '1p'|cut -c 56-99 and what it... (2 Replies)
Discussion started by: beilstwh
2 Replies

10. Shell Programming and Scripting

Text Append

I'm creating a script that counts the number of users currently online, then records that in a file called "log.txt" along with the time. Everytime the script is ran, the script appends the "log.txt" this is what I have: who|wc|cut -c6,7>>log.txt date|cut -c12-24>>log.txt After running... (5 Replies)
Discussion started by: 801238429
5 Replies
Login or Register to Ask a Question