Menghapus Kolom Pertama berkas Text

Saya ada berkas dengan nama text1.txt yang isinya :

178  grep -ri su_parse_csv .
179  grep -r -l su_parse_csv . | xargs sed -i 's/su_parse_csv/su_parse_csvx/g'
180  grep -ri su_hex_shift .
181  grep -r -l su_hex_shift . | xargs sed -i 's/su_hex_shift/su_hex_shiftx/g'
182  grep -ri su_ .
183  grep -r -l su_apply_formatting . | xargs sed -i 's/su_apply_formatting/su_apply_formattingx/g'
184  grep -r -l su_do_shortcode . | xargs sed -i 's/su_do_shortcode/su_do_shortcodex/g'
185  grep -r -l su_compatibility_mode_prefix . | xargs sed -i 's/su_compatibility_mode_prefix/su_compatibility_mode_prefixx/g'
186  grep -r -l su_cmpt . | xargs sed -i 's/su_cmpt/su_cmptx/g'
187  grep -r -l su_ecssc . | xargs sed -i 's/su_ecssc/su_ecsscx/g'
188  grep -r -l su_image_resize . | xargs sed -i 's/su_image_resize/su_image_resizex/g'
189  grep -r -l su_delete_resized_images . | xargs sed -i 's/su_delete_resized_images/su_delete_resized_imagesx/g'
190  grep -r -l su_scattr . | xargs sed -i 's/su_scattr/su_scattrx/g'
191  grep -r -l su_get_icon . | xargs sed -i 's/su_get_icon/su_get_iconx/g'
192  grep -r -l Su_Tools . 
193  grep -ri -l Su_Tools . 
194  grep -ri Su_Tools . 
195  grep -r -l Su_Tools . | xargs sed -i 's/Su_Tools/Su_Toolsx/g'
196  grep -ri Su_Tools . 

Saya hendak menghilangkan angka di kolom angka pada berkas tersebut. Nah, saya perlu menggunakan awk sebagaimana :

  awk '{print substr($0, index($0, $2))}' text1.txt

Maka hasilnya adalah sebagai berikut :

grep -ri su_parse_csv .
grep -r -l su_parse_csv . | xargs sed -i 's/su_parse_csv/su_parse_csvx/g'
grep -ri su_hex_shift .
grep -r -l su_hex_shift . | xargs sed -i 's/su_hex_shift/su_hex_shiftx/g'
grep -ri su_ .
grep -r -l su_apply_formatting . | xargs sed -i 's/su_apply_formatting/su_apply_formattingx/g'
grep -r -l su_do_shortcode . | xargs sed -i 's/su_do_shortcode/su_do_shortcodex/g'
grep -r -l su_compatibility_mode_prefix . | xargs sed -i 's/su_compatibility_mode_prefix/su_compatibility_mode_prefixx/g'
grep -r -l su_cmpt . | xargs sed -i 's/su_cmpt/su_cmptx/g'
grep -r -l su_ecssc . | xargs sed -i 's/su_ecssc/su_ecsscx/g'
grep -r -l su_image_resize . | xargs sed -i 's/su_image_resize/su_image_resizex/g'
grep -r -l su_delete_resized_images . | xargs sed -i 's/su_delete_resized_images/su_delete_resized_imagesx/g'
grep -r -l su_scattr . | xargs sed -i 's/su_scattr/su_scattrx/g'
grep -r -l su_get_icon . | xargs sed -i 's/su_get_icon/su_get_iconx/g'
grep -r -l Su_Tools . 
grep -ri -l Su_Tools . 
grep -ri Su_Tools . 
grep -r -l Su_Tools . | xargs sed -i 's/Su_Tools/Su_Toolsx/g'
grep -ri Su_Tools . 

Lain lagi kalo hanya sekedar menghilangkan kolom kosong (berupa whitespace, misalnya) di awal maka perintahnya adalah :

    cut -d " " -f 3- text2.txt > text3.txt

hasil diff-nya :

samsul@studio:~$ diff text2.txt text3.txt
1,4c1,4
<   178  grep -ri su_parse_csv .
<   179  grep -r -l su_parse_csv . | xargs sed -i 's/su_parse_csv/su_parse_csvx/g'
<   180  grep -ri su_hex_shift .
<   181  grep -r -l su_hex_shift . | xargs sed -i 's/su_hex_shift/su_hex_shiftx/g'
---
> 178  grep -ri su_parse_csv .
> 179  grep -r -l su_parse_csv . | xargs sed -i 's/su_parse_csv/su_parse_csvx/g'
> 180  grep -ri su_hex_shift .
> 181  grep -r -l su_hex_shift . | xargs sed -i 's/su_hex_shift/su_hex_shiftx/g'

Sekian dulu catatan kali ini. Nah, referensinya dari sini.

  • linux/Menghapus.Kolom.Pertama.berkas.Text
  • Terakhir diubah: 5 bulan yang lalu
  • (Perubahan eksternal)