Sponsored Content
Top Forums Shell Programming and Scripting How do you split a sentence after every nth word Post 302439331 by muay_tb on Thursday 22nd of July 2010 09:20:08 AM
Old 07-22-2010
Quote:
Originally Posted by joeyg
Code:
C:\cygwin\tmp>echo a b1 c22 d33 e4 f5 | sed 's/\.* /~/4' | tr "~" "\n"
a b1 c22 d33
e4 f5

I put a ~ after the 4th instance, then convert that to a new-line.
hey joeyg, thanks. However trying your approach doesnt work on the every line, it only works on the first words:

i.e echo "as bg bh bh nj mk mu bg nh dr g y jj ko ll oo ss ff gg yy hh hh" | sed 's/\.* /~/2' | tr "~" "\n"

gave me:
as bg
bh bh nj mk mu bg nh dr g y jj ko ll oo ss ff gg yy hh hh
Smilie

---------- Post updated at 08:19 AM ---------- Previous update was at 08:16 AM ----------

---------- Post updated at 08:20 AM ---------- Previous update was at 08:19 AM ----------

i have re-directed a load of IDs to a temp file which is space separated. The file has more than 2000 rows.

I just need a way of printing each ID out on a new line in groups of 'X' (where X can be 5, 10, 15, etc)...

I am running my script on Solaris 8 and 10 systems.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

2. Shell Programming and Scripting

split a sentence and seperate into two lines

Hi, I have a string as str="route net,-hopcount,1,255.255.255.0,10.230.20.111,10.230.20.234 Route True route net,-hopcount,0,-netmask,255.255.248.0,0,10.230.23.254 Route True" I need to split this string into two lines as route net,-hopcount,1,255.255.255.0,10.230.20.111,10.230.20.234... (4 Replies)
Discussion started by: chaitanyapn
4 Replies

3. Shell Programming and Scripting

How to split a sentence

Hi, Can anybody help me out, how can I split the sentence, 11111 12-12-2002 1000 23 22222 11-11-2011 2000 24 13131 09-02-2002 like the below format, 11111 12-12-2002 1000 23 22222 11-11-2011 2000 24 etc.... Plz help... Thanks in advance...!! (14 Replies)
Discussion started by: Kattoor
14 Replies

4. Shell Programming and Scripting

Truncate the word from a sentence

Hi, The first line of a file is as follows: example.4ge v.45352 Report for April 28 May 2010 I need to remove the word example.4ge v.45353 from that line. I used the following command to truncate it sed 's/example.4ge v.45352//g' $filename But here the version number 45352 may... (4 Replies)
Discussion started by: Kattoor
4 Replies

5. Shell Programming and Scripting

Trim the sentence containing colon and period to extract a word in between

Hello All , i am a newbie in korn shell scripting trying to trim a sentence that is parsed into a variable . The format of the sentence has three words that are separated from other by a " : " colon and "." period . Format of the sentence looks like ... (5 Replies)
Discussion started by: venu
5 Replies

6. Shell Programming and Scripting

Extract a word from sentence

$SET_PARAMS='-param Run_Type_Parm=Month -param Portfolio_Parm="997" -param From_Date_Parm="2011-08-09"' Want to extract the value of "Portfolio_Parm" from $SET_PARAMS i.e in the above case "997" & assigned to new variable. The existence order of "Portfolio"Parm" can change, but the name... (2 Replies)
Discussion started by: SujeethP
2 Replies

7. Shell Programming and Scripting

SED (or other) upper to lowercase, with first letter of first word in each sentence uppercase

The title pretty much defines the problem. I have text files that are all in caps. I would like to convert them to lowercase, but have the first letter of the first word in each sentence in uppercase. I already have SED on the server for fixing / tweaking text files, but I'm open to other... (5 Replies)
Discussion started by: dockline
5 Replies

8. Shell Programming and Scripting

match sentence and word adn fetch similar words in alist

Hi all, I have ot match sentence list and word list anf fetch similar words in a separate file second file with 2 columns So I want the output shuld be 2 columns like this (3 Replies)
Discussion started by: manigrover
3 Replies

9. Shell Programming and Scripting

How to grep nth word in line?

my input file content is like this GEFITINIB 403 14 -4.786873 -4.786873 -1.990111 0.000000 0.000000 -1.146266 -39.955912 483 VANDETANIB 404 21 -4.754243 -4.754243 -2.554131 -0.090303 0.000000 -0.244210 -41.615502 193 VANDETANIB 405 21 -4.737541 -4.737541 -2.670195 -0.006006 0.000000 -0.285579... (4 Replies)
Discussion started by: chandu87
4 Replies

10. Shell Programming and Scripting

Remove First word of a sentence in shell

Hi there, How I remove the first word of a sentence. I have tried. echo '1.1;' ; echo "$one" | grep '1.1 ' | awk '{print substr($0,index($0," ")+1)}' For the below input. 1.1 Solaris 10 8/07 s10s_u4wos_12b SPARC Just want to know if there is any shorter alternative. (3 Replies)
Discussion started by: alvinoo
3 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 02:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy