Replacing Multiple spaces with a single space but excluding few regular expressions
Hi All.
Attached are two files.
I ran a query and have the output as in the file with name "FILEWITHFOURRECORDS.txt "
I didn't want all the spaces between the columns so I squeezed the spaces with the "tr" command and also added a carriage return at the end of every line.
But in two columns I.e., the second and third column, I have a description where it has spaces in between and it should NOT be removed. But as I apply a 'tr' on the whole file, even those spaces are removed.
Could you please help me, how to retain the spaces in that string and replace everything else.
Below is how it looks after removing spaces:
It should look like this:
Any suggestion will be very helpful. Please let me know if my question is not clear!
There are no double quotes in FILEWITHFOURRECORDS.txt, so how did your code generate them? Without any separators/tokens/indicators, how can we tell where $2 stops and $3 starts?
---------- Post updated at 23:29 ---------- Previous update was at 23:21 ----------
or do field2 and 3 always have five comma separated elements?
My bad, That result was from a query which I executed before, but the 2nd and 3rd fields does have the quotes around it.
And to your questions $2 and $3 have four or sometimes five comma separated elements
My bad, That result was from a query which I executed before, but the 2nd and 3rd fields does have the quotes around it.
And to your questions $2 and $3 have four or sometimes five comma separated elements
So, your real data contains double quotes surrounding fields 2 and 3, but the sample data you've shown us contains no double quotes? And, without the quotes fields 2 and 3 sometimes contain 3 commas and sometimes contain 4 commas. So how are we supposed to guess where to add the double quotes?
I am confused.
Can you please show us the output from your query that contains the double quotes and show us the output you hope to produce from that output? (Please post samples in-line in a post (in CODE tags) if at all possible instead of uploading files that everyone who wants to help you has to download.)
Im looking for a bash solution that will use Regular Expressions (not perl, sed or awk) to check the example data below and then give me a status.
which would be just simply Match or Mismatch.
SYS PS1 is present.
Fan status: Normal
Input Voltage status: Normal
... (5 Replies)
I am looking for a regular expression that uses sed to replace multiple spaces with single spaces on every line where it is not at the start of the line and not immediately before double slashes ('//') or between quotes (").
In its simplest form, it would look like this:
sed -e 's# # #g'... (4 Replies)
Platform : RHEL 5.8
I want to end each line of this file with a single quote.
$ cat hello.txt
blueskies
minnie
mickey
gravity
snoopyAt VI editor's command mode, I have used the following command to replace the last character with a single quote.
~
~
~
:%s/$/'/gNow, the lines in the... (10 Replies)
I am trying to read a txt file and trying to translate multiples spaces into single spaces so the file is more organized, but whenever I try the command:
tr ' ' ' ' w.txt
The output is:
tr: extra operand `w.txt'
Try `tr --help' for more information.
Can someone please help? :wall:
... (2 Replies)
Hi All,
Can please let me know what is the difference between the single line mode and multi line mode in regular expresions?
Thanks,
Chidhambaram B (3 Replies)
consider the small piece of code
while read line
do
echo $line
done < example
content of example file
sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr
the output is like
sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr
the... (4 Replies)
Hello,
I need help with using grep and regular expressions....
I have a long list of about 1000 lines of Chinese flashcards. Here's a small excerpt:
意文 yìwén (given name)
貴姓 guìxìng (honorable surname)
貴 guì (honorable)
姓 xìng (one's surname is; to be surnamed; surname)
呢 ne (interrogative... (2 Replies)
I am searching while I await a response to this so if it has been asked already I apologize.
I have a file with lines in it that look like:
bob johnson email@email.org
I need it to look like:
bob:johnson:email@email.org
I am trying to use sed like this:
sed -e 's/ /:/g' file >... (5 Replies)
I'm reading from a file that is semi-colon delimited. One of the fields contains 2 spaces separating the first and last name (4th field in - "JOHN<space><space> DOE"):
e.g. TORONTO;ONTARIO;1 YONGE STREET;JOHN DOE;CANADA
When I read this record and either echo/print to screen or write to... (4 Replies)
I want to write a script which will check the arguments and if there is a single space(if 2 more more space in a row , then do not touch), replace it with _ and then gather the argument
so, program will be ran
./programname hi hello hi usa now hello hello
so, inside of program,... (7 Replies)