Add a new line


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Add a new line
# 1  
Old 04-22-2010
Add a new line

when I am running the below inside my script
Code:
export MEMORY_CPU_USAGE1=`ssh ${OLC_1_USER}@${OLC_1_HOST} prstat -t -n 10 1 5 | awk '!/MEMORY/ && !/lwps,/ && !/CPU/ && !/ave
rages:/ { if( $5 > "1%" || $7 > "2%" )  print $0  ","}'`
echo ${MEMORY_CPU_USAGE1}

output:
Code:
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%, 75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6%, 31 sbswrk2 3624M 3720M 5.7% 997:34:53 0.1%, 75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6%, 26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%,


I want the output to be with newline instead of comma so i changed it at the last place still it is not comming in new line.
Code:
export MEMORY_CPU_USAGE1=`ssh ${OLC_1_USER}@${OLC_1_HOST} prstat -t -n 10 1 5 | awk '!/MEMORY/ && !/lwps,/ && !/CPU/ && !/ave rages:/ { if( $5 > "1%" || $7 > "2%" ) print $0 "\n"}'` 
echo ${MEMORY_CPU_USAGE1}

Now the output looks :


Code:
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6% 75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6% 31 sbswrk2 3624M 3720M 5.7% 997:34:53 0.1%,75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6% 26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%



I wanted it to be like this
Code:
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6% 
75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6% 
31 sbswrk2 3624M 3720M 5.7% 997:34:53 0.1%
75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6% 
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%


Thanks

Last edited by vgersh99; 04-22-2010 at 11:56 AM.. Reason: code tags, please!
# 2  
Old 04-23-2010
Code:
[house@discovery] echo "26 [...] 0.6%," | sed -e 's/, /\n/g' -e 's/,//g'
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%
75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6%
31 sbswrk2 3624M 3720M 5.7% 997:34:53 0.1%
75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6%
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%

# 3  
Old 04-26-2010
Using your oringal output of

Code:
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%, 75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6%, 31 sbswrk2 3624M 3720M 5.7% 997:34:53 0.1%, 75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6%, 26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%,


Just pipe your output to the below awk statement.
Code:
 | awk '{ gsub (",", "\n") }$0'

# 4  
Old 05-05-2010
MySQL

Quote:
Originally Posted by dr.house
Code:
[house@discovery] echo "26 [...] 0.6%," | sed -e 's/, /\n/g' -e 's/,//g'
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%
75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6%
31 sbswrk2 3624M 3720M 5.7% 997:34:53 0.1%
75 sbswrk1 2724M 2800M 4.3% 805:28:00 0.6%
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6%

This code does not give that wanted solution ..

Instead of this Smilie

Code:
# cat inputfile
26 sbswrk3 4573M 4673M 7.1% 636:23:50 0.6% 75 sbswrk1 2724M..... 4673M 7.1% 636:23:50 0.6%

Code:
# sed -e 's/% /%\n/g' inputfile | sed 's/,/\n/' | sed -e '/%$/{;N}' -e 's/%\n/%/g'
26 sbswrk3 4573M 4673M 7.1%636:23:50 0.6%
75 sbswrk1 2724M 2800M 4.3%805:28:00 0.6%
31 sbswrk2 3624M 3720M 5.7%997:34:53 0.1%
75 sbswrk1 2724M 2800M 4.3%805:28:00 0.6%
26 sbswrk3 4573M 4673M 7.1%636:23:50 0.6%

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

2. Shell Programming and Scripting

How to add the line to previous line in | delimited text?

Hi All, I am new to Unix and I have one challenge and below are the details. I have pipe delimited text file in that data has span into multiple lines instead of single line. Sample data. Data should be like below for entire file. 41|216|398555|77|provided complete NP outcome data ... (21 Replies)
Discussion started by: Narasimhasss
21 Replies

3. Shell Programming and Scripting

How to add line to previous line if not a number?

Hi, I am trying to compare 2 lists. However, one of these lists has to be taken from a.pdf file. When I copy the test into a .txt document there are formatting errors which I need to correct. The document is long (~10,000 lines) so I need to script the re-formatting. Currently my file looks... (9 Replies)
Discussion started by: carlr
9 Replies

4. Shell Programming and Scripting

Choose a line-number to add line

Hello guys, I'm making a script to add visudo with this script. Do you guys know if it's possible to add words to a line-number you want to. Something like this: echo "Adding words to line-number 16" >> /etc/sudoers # (options to add to line-number-16)? Thanks! (3 Replies)
Discussion started by: dannyvdberg
3 Replies

5. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

6. Shell Programming and Scripting

add number in lines line by line in different files

I have a set of log files that are in the following format ======= set_1 ======== counter : 315 counter2: 204597 counter3: 290582 ======= set_2 ======== counter : 315 counter2: 204597 counter3: 290582 ======= set_3 ======== counter : 315 counter2: 204597 counter3: 290582 Is... (6 Replies)
Discussion started by: grandguest
6 Replies

7. Shell Programming and Scripting

howto add line as a first line into a non empty file

Hi Trying to do like this : echo "$variable1\n $(cat file.txt)" but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1. How to add constantly line into first line in file ? (3 Replies)
Discussion started by: presul
3 Replies

8. Shell Programming and Scripting

Add new parameters into a line, and redirect the line to other file

How can i add new parameters into a line, and redirect the line to other file? For example: 1.sh name:owner google:richard youtube:student I want a, for example 2.sh with: name:owner:description google:richard:search site youtube:student:video site In the 2.sh, I added a new column:... (7 Replies)
Discussion started by: rafazz
7 Replies

9. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

10. Shell Programming and Scripting

SED help (remove line::parse again::add line)

Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions,... (6 Replies)
Discussion started by: Malumake
6 Replies
Login or Register to Ask a Question