Command Line To Remove Column 10 From A .csv File

Hello. I am new to Linux and am looking for a solution to remove column 10 from a .csv data file as this column is causing me problems. Any help would be appreciated.
Thank you!


Similar Content



Remove Column From .CSV Using AWK Command

Hi,

I am trying to remove the Column from .CSV using Awk Command. Below is the input

Name,Age,Description,Location
Gopal,32,Tech Lead,"Ramnagar, Naintal"
Gaurav,24,"Linux Admin, Expert","Noda"

I want column 1,2,4 and i am using below mention command

awk -F, ' BEGIN { OFS="," }
{
print $1,$2,$4
}' new.csv > new-done.csv


but instead of getting Gaurav,24,Noda

i am getting

Name,Age,Location
Gopal,32,"Ramnagar
Gaurav,24, Expert"

Print Column With A String Using Awk Or Grep

Hi All,

Using grep command with a defined string, you will get the row. Can I get the column instead of row? For example,

the file content is as below:

AA BB
123 456
789 ABE

execute 'grep ABE file' will give you "789 ABE". Is there any way to get the column:
BB
456
ABE
?

Thank you very much.

Sed Creating An Extra File With E At The File Name

Hi Members,

I've file named A200205__mlst__Staphylococcus_aureus__results.txt
It has column 1 as:

Quote:
Sample
A200205_GGTGAGTT_L007
I'm running below command:
Quote:
sed -ie s/out_paired_//g A200205__mlst__Staphylococcus_aureus__results.txt
It replaces out_paired_ in line 2 of column 1 to null.
I'm having the desired output, however, surprisingly a new file is created with name A200205__mlst__Staphylococcus_aureus__results.txte; i.e an extra e

I am unable to figure it out the cause of this hack!

How To Delete Header (first Row) And First Column From Multiple CSV Files

I have several of csv files, I want to remove the first row (header) and first column as well. This is my code, but it overwrites the original files with no content inside:

for x in *.csv;
do
sed '1d' $x | cut -d, -f 1 > "$x";

done

Help would be highly appreciated.

Send Emails In HTML Format Through Mailx

I have created a sql file and it will create a HTML file with query result.But I'm unable to retrieve a html body in my email instead am getting a mail body with html tags.Please help

sql----

--sample HTML report.
--
-- Usage: sqlplus LOGON @script OUTPUT_FILENAME
--

-- Activate HTML output and configure the generated markup.
SET MARKUP HTML ON SPOOL ON -
HEAD '<title>My Report</title> -
<style type="text/css"> -
table { background: #eee; font-size: 80%; } -
th { background: #ccc; } -
td { padding: 0px; } -
</style>'

-- Dump results to the file that is given on the command line.
SPOOL &1

-- Only dump to file, not to the terminal.
SET TERMOUT OFF

-- Titles and formatting of columns.
COLUMN name HEADING 'Name'
--COLUMN job HEADING 'Job Title'
--COLUMN salary HEADING 'Salary' FORMAT $99,990

-- The query
--
select tablespace_name from dba_tablespaces;
/

-- Close file, which also closes the HTML tags.
SPOOL OFF

-- Back to non-HTML output
SET MARKUP HTML OFF


mailx command----

mailx -s 'file system' c.bambarandage@prima.com.lk < sam.html

Thanks,
Charith.

How To Escape A FS In A CSV Text And Help With Formatting

Hi Linux Experts,

I have the following problem to solve:

-Below is the CSV file give

firstname,lastname,password,username,notes,city,phonenumber
fred,smith, notgood1, fredsmith, this user\, is the first in this file, Brighton,345698
Peter, Bloggs, anotherbad,peterbloggs,,London,987123
Jo, cooper, notmuch, jcooper, this user is Jo, Brighton, 456987
john, carter,nearlyempty,jcarter,This note is actually very long\, but really doesn't say anything very useful,,345777
sam,jones,passing, samjones, Not much of a note really, Manchester, 135790

- capitalise the first letter of the two name fields
- sanitise the formatting
- move the username column to the beginning of each line
- the phone number is missing the area code - look up the city in the following table, and add it to the beginning of the phone number column:

City, Area Code
London, 5
Brighton, 6
Manchester, 7

Provide the corrected CSV file.

One of the problems I have is that whenever I use the comma as FS the output for column 5 is the following

cat Test.csv | awk 'BEGIN { FS = "," } {print $5 }'
notes
this user\

this user is Jo
This note is actually very long\
Not much of a note really

It stops in the middle of the entry because it sees the comma but what I am trying to achieve is to produce the full entry for column 5 like this:

this user\, is the first in this file
This note is actually very long\, but really doesn't say anything very useful

I have to probably escape somehow the FS in the text but so far no joy with completing this task. Also can you kindly help out for the rest of the requirements.
I really appreciate your help in advance.

Ivan

Would Like To "echo" A Line, "read" Reply, Then Execute The Reply: How In Bash?

Apologies. I've been out of Unix for 14 years, and the gears have rusted. Also, Unix has changed - enough similarities to memory that I'm pretty comfy though.

Glad to see lots of info available via google. However changes are going to take getting used to. Have set up a testbed of 3 nearly identical machines, hoping to make an (at home) private network where I can automate installs and set-ups using NIS and NFS (Similar to work I once did).

Have found useful scripts interspersed with comments, would like to copy and paste them to a bash script that:

Reads the line.
Echos the line.
Reads the reply.
Executes what is typed.

Essentially, by making myself type (or copy & paste) the commands I think I'll become familiar.

Figured I'd use a spreadsheet, select the file, and paste into column B of the spreadsheet. In column A I'd paste:

echo "

and in column C I'd paste:

"

Then I'd cut and paste into a text document, insert the lines:

read A
$A

behind every command necessary to the actual task.

Figured I'd have to escape the ' and ".

Ran a test (test.bash):

#!/bin/bash
for i in `seq 1 10`;
do
echo "Enter a command:"
read A
echo "Trying $A"
$A
done

works fine when I type

ls -alg

but not so when I type

ls -alg | grep dwrx

so I'm wondering if someone has a suggestion?

Thanks for any ideas.

Need Help On Csv Formatting

I need cleaning and altering the CSV in the following ways:

* capitalise the first letter of the two name fields
* sanitise the formatting
* move the username column to the beginning of each line
* the phone number is missing the area code - look up the city in the following table, and add it to the beginning of the phone number
column

City, Area Code
London, 5
Brighton, 6
Manchester, 7

Tha CSV file look like:

Code:
firstname	lastname	password	username	notes	city	phonenumber	
fred	smith	 notgood1	 fredsmith	 this user\	 is the first in this file	 Brighton	345698
Peter	 Bloggs	 anotherbad	peterbloggs		London	987123	
Jo	 cooper	 notmuch	 jcooper	 this user is Jo	 Brighton	456987	
john	 carter	nearlyempty	jcarter	This note is actually very long\	 but really doesn't say anything very useful		345777
sam	jones	passing	 samjones	 Not much of a note really	 Manchester	135790


I wrote a script but it capitalized all the column:

sed -e "s/\b\(.\)/\u\1/g" test.csv

Please suggest.

Perl One Liner To Delete Line In Csv File If One Columns Is Toobig

I have a little bash script that cats out a file and tells me if there is a line
where the 11th column has more than 6 characters in it.
It emails me where there is a bad line in a file - bead meaning that it will break a
donwstream process.

anyhow when i get the email saying that there is a bad file i just log in to the pc via
vpn and the I sed out the lines from the file that I get in the email. The bad lines are
always in danny.csv not danny1.csv
It has been the same lines killing the downstream process for a few weeks, so i put the "sed -i's" into
the script and it does it automagically.

[CODE]
for i in danny.csv danny1.csv
do
cat /come/and/play/with/$i | perl -ne 'print if length((split /,/)[10]) > 6' | mail -s "danny.csv bad line" casper@casperr.com
done

#it would be nice to find a perl change the file in place
sed -i '/D,642,0642,UBF,EVL,,M,,S,S,FOREVER,213,213,/d' /come/and/play/with/us/danny.csv
sed -i '/D,642,0642,UBF,EVL,,M,,S,S,QSP-U=C,4,4,/d' /come/and/play/with/us/danny.csv
[CODE]

However when a new line gets put into this file, I am going to have to log in and take out the line.
SO I have been trying to write a perl one liner that will edit the file in place, like sed, and make a
backup of the file. I just need a perl one liner that will delete any line where the 11th columns has more
than 6 characters in it.
[CODE]
perl -p -i.bak -e 's/\,\w{7}\,//g - which does not work.
[CODE]
I tried something like this:

[CODE]
perl -nle 'print if /\,\w{7}\,/' /come/and/play/with/us/danny.csv
[CODE]
but that does not catch the QSP-U=C and it catches more lines than just the
FOREVER. for a solutinog I need to focus on the the 11th column.

Having Problem While Inserting New Enteries In Csv File

Hi Experts,

I am trying to make new enteries in a csv file in new column but am not able to do so.Please help for the same.

Requirement:

There are multiple directories & within those directories i have sub-directories and i want to build a csv file with 2 columns of Directories mapped to their sub-directories. Can you please help me with this. I tried the following code:

Code:
#!/bin/bash

homeDir="$HOME"



ls ~/Parent/ | cut -c1-9 > ~/test_111.csv

while read Child

do

Entry="$(ls $homeDir/Parent/$Child/ABC/XYZ/DEF/PQR)"

echo $Entry

for (( c=1; c<=5; c++ ))

do



sed -i ci"$Entry" test_222.csv

done


done < test_111.csv

Basically i want two columns of csv file , First column should have Child name & Second cloumn should have Sub-Directory name inside PQR Directory.

Any help will be useful on this.

Thanks in Advance!

Best Regards,
Vijay Bhatia