Format output from "echo" command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Format output from "echo" command
# 1  
Old 08-05-2010
Format output from "echo" command

Hi,

I have written a BASH shell script that contains a lot of "echo" commands to notify the user about what's going on. The script generates a log file that contains a copy of what is seen in the terminal. The echo statements are generally verbose, and thus extend out for quite a ways on one line. This results in a messy looking log file that also often has to be resized in order to be completely viewed.

I would like to format the output of these echo commands according to the following rules 1) If a statement is greater than 75 characters (for example) it will be broken up into multiple lines, where each line never exceeds 75 characters, 2) when parsing a statement into different lines, individual words won't get split between two adjacent lines.

In my mind I have the idea that I could have a function called something like "format_echo_statement", and every time in my script I would like to echo a statement I would do the following:

echo_statement='This is an example echo statement that exceeds 75 characters. It will need to be formatted and split into multiple lines so my log file does not look messy'

#Call the function "format_echo_statement":
format_echo_statement ${echo_statement}

However, the innards of the function are perplexing me. Any ideas on how to accomplish this? Thanks in advance.

Mike
# 2  
Old 08-05-2010
look into the fold command
# 3  
Old 08-05-2010
Or the "fmt" command with options "-s -w 75".
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

3. Shell Programming and Scripting

"links -dump" output format issue

Hi All, I tried searching a lot about this but to no avail. I have a HTML file. I used links -dump file_page.html > text_html.txt What the above command gave me was a filtered text from the HTML file with tags removed. Now, the the output from the above command looked something like this:... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Amend format of output from "last"command

When I run a “last” command, I am getting more than one row per user. Eg userabc pts/2 10.253.0.108 Tue Dec 14 09:21 still logged in userabc pts/2 10.253.0.108 Tue Dec 14 03:57 - 03:59 (00:01) userabc pts/2 10.253.0.108 Mon Dec 13 14:25 - 15:43 (01:18) userpqr pts/3 10.253.0.39 Wed Jan... (5 Replies)
Discussion started by: malts18
5 Replies

6. Shell Programming and Scripting

Format output from the file to extract "date" section

Hello Team , I have to extract date section from the below file output. The output of the file is as shown below. I have to extract the "" this section from the above output of the file. can anyone please let me know how can we acheive this? (4 Replies)
Discussion started by: coolguyamy
4 Replies

7. UNIX for Dummies Questions & Answers

Explanation of "total" field in "ls -l" command output

When I do a listing in one particular directory (ls -al) I get: total 43456 drwxrwxrwx 2 root root 4096 drwxrwxrwx 3 root root 4096 -rwxrwxr-x 1 nobody nobody 3701594 -rwxrwxr-x 1 nobody nobody 3108510 -rwxrwxr-x 1 nobody nobody 3070580 -rwxrwxr-x 1 nobody nobody 3099733 -rwxrwxr-x 1... (1 Reply)
Discussion started by: proactiveaditya
1 Replies

8. Shell Programming and Scripting

ksh script that echo " please insert your name " and store the output to a login.log file.

Hello All Nice to meet you all here in this forum, it's my 1rst time here i'm asking about a little issue that i face i added a ksh script that echo " please insert your name " and store the output to a login.log file. the script is working fine with normal telnet but Xstart is not working... (8 Replies)
Discussion started by: islam.said
8 Replies

9. Shell Programming and Scripting

how to include "*" in echo command????

Hi All, I am doing one simple web tool. I have a HTML as my front end and cgi as my backend. Here my pb is when I assign the html form input to a variable in my script, it is not accepting the special char "*" to that varible. say I have a text box(Name : in_query) in html and trying to... (1 Reply)
Discussion started by: askumarece
1 Replies

10. Shell Programming and Scripting

Need a Command To display "echo command value in loop" in single line.

Hi I want to display "echo command value in loop" in single line. My requirement is to show the input file (test_1.txt) like the output file (test_2.txt) given below. Input file :test_1.txt a1|b1|4|5 a1|b1|42|9 a2|b2|32|25 a1|b1|2|5 a3|b3|4|8 a2|b2|14|6 Output file:test_2.txt... (2 Replies)
Discussion started by: sakthifire
2 Replies
Login or Register to Ask a Question