# Remove head for all the files

**URL:** <https://community.unix.com/t/remove-head-for-all-the-files/296628>\
**Category:** Shell Programming and Scripting\
**Created:** [October 5, 2011, 7:38am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628 "2011-10-05T07:38:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![baskivs](https://community.unix.com/letter_avatar/baskivs/32/5_5575768a8748004e209b776fc1b2916d.png) [@baskivs](https://community.unix.com/u/baskivs)\
**Post date:** [October 5, 2011, 7:38am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/1 "2011-10-05T07:38:11Z")

</div>

Hi all,

i need to remove the header for all the files which is ending with .csv and append into one file

example,

```nohighlight
test1.csv
test2.csv
test3.csv

```

i tried with the below command,

```nohighlight
sed '1d' test*.csv> appendnew.csv

```

but it deletes only the first file header. and appending all the files

Thanks,  
baski

---

<div class="post-metadata">

**Author:** ![jayan\_jay](https://community.unix.com/user_avatar/community.unix.com/jayan_jay/32/1006_2.png) [@jayan\_jay](https://community.unix.com/u/jayan_jay)\
**Post date:** [October 5, 2011, 7:42am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/2 "2011-10-05T07:42:24Z")

</div>

```nohighlight
$ for i in test*.csv; do sed '1d' $i >> append.csv; done

```

---

<div class="post-metadata">

**Author:** ![aigles](https://community.unix.com/user_avatar/community.unix.com/aigles/32/118_2.png) [@aigles](https://community.unix.com/u/aigles)\
**Post date:** [October 5, 2011, 7:42am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/3 "2011-10-05T07:42:46Z")

</div>

A possible solution :

```nohighlight
awk 'FNR>1' test*.csv> appendnew.csv

```

Jean-Pierre.

---

<div class="post-metadata">

**Author:** ![ahamed101](https://community.unix.com/user_avatar/community.unix.com/ahamed101/32/1118_2.png) [@ahamed101](https://community.unix.com/u/ahamed101)\
**Post date:** [October 5, 2011, 7:43am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/4 "2011-10-05T07:43:27Z")

</div>

```nohighlight
awk 'FNR>1{print}' *.csv > out_file

```

--ahamed

---

<div class="post-metadata">

**Author:** ![michaelrozar17](https://community.unix.com/user_avatar/community.unix.com/michaelrozar17/32/1975_2.png) [@michaelrozar17](https://community.unix.com/u/michaelrozar17)\
**Post date:** [October 5, 2011, 7:46am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/5 "2011-10-05T07:46:43Z")

</div>

> [@baskivs](#):
>
> ```plaintext
> sed '1d' test*.csv> appendnew.csv
> 
> ```
> 
> but it deletes only the first file header. and appending all the files

Are you sure that its appending all the test\*.csv files to appendnew.csv..? Try with `>>` instead of `>`

---

<div class="post-metadata">

**Author:** ![baskivs](https://community.unix.com/letter_avatar/baskivs/32/5_5575768a8748004e209b776fc1b2916d.png) [@baskivs](https://community.unix.com/u/baskivs)\
**Post date:** [October 5, 2011, 8:35am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/6 "2011-10-05T08:35:19Z")

</div>

Thanks for all your replies,

i m just expanding my query,

i can able to delete and append by using the below comman,

```nohighlight
awk 'FNR>1{print}' *.csv >> out_file
 

```

and i aslo need some particular columns in the csv files , so i tried with this

```nohighlight
awk -F"," -v OFS=',' '{print $1, $2,$8}' *csv >> outfile1
 

```

above also working fine but i need to merge it into single awk command and also need to sort the cloumns on w.r.t column $2  
pls help me on this

thanks,  
Baski

---

<div class="post-metadata">

**Author:** ![ahamed101](https://community.unix.com/user_avatar/community.unix.com/ahamed101/32/1118_2.png) [@ahamed101](https://community.unix.com/u/ahamed101)\
**Post date:** [October 5, 2011, 8:40am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/7 "2011-10-05T08:40:04Z")

</div>

```nohighlight
awk -F"," -v OFS="," 'FNR>1{print $1,$2,$8}' csv >> outfile1

```

--ahamed

---

<div class="post-metadata">

**Author:** ![aigles](https://community.unix.com/user_avatar/community.unix.com/aigles/32/118_2.png) [@aigles](https://community.unix.com/u/aigles)\
**Post date:** [October 5, 2011, 8:40am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/8 "2011-10-05T08:40:43Z")

</div>

```nohighlight
awk -F"," -v OFS=',' 'FNR>1 {print $1, $2,$8}' *csv >> outfile1

```

Jean-Pierre.

---

<div class="post-metadata">

**Author:** ![baskivs](https://community.unix.com/letter_avatar/baskivs/32/5_5575768a8748004e209b776fc1b2916d.png) [@baskivs](https://community.unix.com/u/baskivs)\
**Post date:** [October 5, 2011, 9:57am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/9 "2011-10-05T09:57:14Z")

</div>

Thanks a lot ahamed,

and i need to sorting the outputfile w.r.t to $8

Regards,  
Baski

---

<div class="post-metadata">

**Author:** ![ahamed101](https://community.unix.com/user_avatar/community.unix.com/ahamed101/32/1118_2.png) [@ahamed101](https://community.unix.com/u/ahamed101)\
**Post date:** [October 5, 2011, 9:59am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/10 "2011-10-05T09:59:53Z")

</div>

```nohighlight
awk '{...}' input_file | sort -k3 -t, >> out_file

```

You are welcome! 🙂

--ahamed

---

<div class="post-metadata">

**Author:** ![baskivs](https://community.unix.com/letter_avatar/baskivs/32/5_5575768a8748004e209b776fc1b2916d.png) [@baskivs](https://community.unix.com/u/baskivs)\
**Post date:** [October 5, 2011, 10:22am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/11 "2011-10-05T10:22:11Z")

</div>

thanks ahamed,

above is working fine.. and also i need to sort the file w.r.t column $8

Thanks,  
BAski

---

<div class="post-metadata">

**Author:** ![ahamed101](https://community.unix.com/user_avatar/community.unix.com/ahamed101/32/1118_2.png) [@ahamed101](https://community.unix.com/u/ahamed101)\
**Post date:** [October 5, 2011, 11:53am UTC](https://community.unix.com/t/remove-head-for-all-the-files/296628/12 "2011-10-05T11:53:20Z")

</div>

Assuming, $8 in the output file is the 3rd field, `sort -k3 -t,` should sort it.

Can you paste the output of the awk command?

--ahamed
