awk problem underlining text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk problem underlining text
# 1  
Old 07-24-2017
awk problem underlining text

I have a whole text file filled with titles of books and its writers and the publications houses etc. Example:

Quote:
- Joseph Campbell, This business of the Gods, in conversation with Fraser Boa, Windrose Films Ltd, Ontario, 2000
I want to underline the title:" This business of the Gods".
An awk line can do the trick, but I have not been able to get it together.

Quote:
The title:
$2
Underline can be done with tput, like this:
BU=`tput smul`
EU=`tput rmul`
echo "${BU}All underline${EU}"
And the field seperator is:
FS= ,
I am close but I can't make it work.
# 2  
Old 07-24-2017
Since you are close...

What is your current awk command, that is close to correct?
# 3  
Old 07-24-2017
Hello TheoDore4,

Welcome to forums, I hope you will enjoy sharing/learning knowledge here.
For your question, if underline means here to get that specific part then following may help you in same.
Code:
awk -F", " '{print $2}'  Input_file

Also feel free to ask questions or queries, happy learning Smilie

Thanks,
R. Singh
# 4  
Old 07-24-2017
First of all, thank you for your anwers.

I want to print the entire line, but $2 must be underlined. So it becomes like this:
Quote:
- Joseph Campbell, This business of the Gods, in conversation with Fraser Boa, Windrose Films Ltd, Ontario, 2000
And not just this line but all the lines in a text file.

I have tried to write a script to accomplish this:
Quote:
#!bin/bash
BU=`tput smul`
EU=`tput rmul`
$2 = {BU}$2{EU}
awk '{ print $0 }'
But this script doesn't work.
# 5  
Old 07-24-2017
Assuming your terminal can do it, you could use a terminal escape code something like this:-
(OSX 10.12.5, default bash terminal.)
Code:
Last login: Mon Jul 24 13:59:56 on ttys000
AMIGA:barrywalker~> TEXT="This business of the Gods"
AMIGA:barrywalker~> printf "\033[4m%s\033[0m\n" "$TEXT" 
This business of the Gods          #This sentence is underlined from the terminal escape code and reset at the end of the sentence.
AMIGA:barrywalker~> _

As for your field separators ' ,' your second field, (the sentence), must not have spaces or commas in it. Better to have the comma only and do a workaround if necessary.
# 6  
Old 07-24-2017
That is not the solution that I am looking for, wisecracker.
I have a list of books of six pages long. I cannot define every single title.

The book written by Joseph Campbell is just given as an example. Every other book in this list has the same structure.
# 7  
Old 07-24-2017
On the Bash shell:
Code:
BU=$(tput smul)
EU=$(tput rmul)
awk -F, -vBU=${BU} -vEU=${EU} 'BEGIN{OFS=","}{$2 = BU$2EU}1' <your_data_file_name>

Replace <your_data_file_name> with the actual name of your data file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to skip lines find text and add text based on number

I am trying to use awk skip each line with a ## or # and check each line after for STB= and if that value in greater than or = to 0.8, then at the end of line the text "STRAND BIAS" is written in else "GOOD". So in the file of 4 entries attached. awk tried: awk NR > "##"' "#" -F"STB="... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

Problem with a text file

Hi, I have many text files with certain problem. It gets fixed by doing vi and delete first line (supposedly a blank line) by pressing dd and save the file. I need to automate this process and I tried sed '1d' samp.pgn and/or unix2dos / dos2unix etc. but NONE of them worked. Strange thing... (4 Replies)
Discussion started by: prvnrk
4 Replies

3. Shell Programming and Scripting

Grep text matching problem with script which checks if web page contains text.

I wrote a Bash script which checks to see if a text string exists on a web page and then sends me an email if it does (or does not e.g. "Out of stock"). I run it from my crontab, it's quite handy from time to time and I've been using it for a few years now. The script uses wget to download an... (6 Replies)
Discussion started by: gencon
6 Replies

4. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

5. Shell Programming and Scripting

Complex text parsing with speed/performance problem (awk solution?)

I have 1.6 GB (and growing) of files with needed data between the 11th and 34th line (inclusive) of the second column of comma delimited files. There is also a lot of stray white space in the file that needs to be trimmed. They have DOS-like end of lines. I need to transpose the 11th through... (13 Replies)
Discussion started by: Michael Stora
13 Replies

6. Shell Programming and Scripting

Extracting text from within a section of text using AWK

I have a command which returns the below output. How can I write a script to extract mainhost and secondhost from this output and put it into an array? I may sometimes have more hosts like thirdhost. I am redirecting this output to a variable. So I guess there should be a awk or sed command to... (7 Replies)
Discussion started by: heykiran
7 Replies

7. Shell Programming and Scripting

Problem with formatting text with awk

I want the following output: User ID: 4071 Last Name: Gills First Name: Roberts Address: Maple Dr. Phone#: 702346789 from this command: grep "$uId" database.txt | awk -F":" '{print "User ID:\t"$uId"\nLast Name:\t"$lname"\n...etc. }' But all I get is this: User ID:... (3 Replies)
Discussion started by: yonkers062986
3 Replies

8. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

9. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

10. UNIX for Dummies Questions & Answers

underlining

can unix underline any words ?? like <u>Time-»_( 07:54:50 )_ Date-»( Fri Aug 29 )</u> (8 Replies)
Discussion started by: SeeD
8 Replies
Login or Register to Ask a Question