Showing posts with label gnu. Show all posts
Showing posts with label gnu. Show all posts

Tuesday, June 20, 2017

Posted by beni in , , , , , , , , | June 20, 2017

A Collection of 60 GNU sed Command Line Examples



This article is a long compilation of our six series of GNU sed command line examples. This article contains more than 60 command lines divided in 6 part. This is intended for those who want to practice, hence this article contains no explanation for every example. We hope this helps you to learn GNU sed easier.


GNU sed Examples The Series


  • Episode 1
  • Episode 2
  • Episode 3
  • Episode 4
  • Episode 5
  • Episode 6

Part 1


1. Read Text File

sed r text.txt


2. Find & Replace

sed �s/UNIX/MINIX/g� text.txt


3. Find & Replace (g Flag)

  1. echo �UNIX UNIX UNIX� | sed �s/UNIX/GNU/g�
  2. echo �UNIX UNIX UNIX� | sed �s/UNIX/GNU/�
4. Find & Replace (Uppercase)
  1. sed �s/have/U&/g� text.txt
5. Find & Replace (Lowercase)
  1. sed �s/UNIX/L&/g� text.txt
  2. sed �s/GNU/L&/g� text.txt
  3. echo �UNIX MINIX� | sed �s/MINIX/L&/g�
6. Delete All Lines
  1. sed �d� text.txt
  2. sed -i �d� text.txt
  3. sed �d� text.txt > new_text.txt
7. Delete Particular Line
  1. sed �1d� text.txt
  2. sed �1,3d� text.txt
  3. sed �4,6d� text.txt
8. Delete All Blank Lines
sed �/^$/d� text.txt

9. Reverse Delete Blank Lines
sed �/^$/!d� text.txt

10. Delete Lines Containing Particular String
sed �/UNIX/d� text.txt


Part 2


11. Find & Replace (Specific Line)
  1. sed 3 s/bsd/U&/g text2.txt
  2. sed 1 s/gnu/U&/g text2.txt
  3. sed 2 s/unix/U&/g text2.txt
12. Find & Replace (Column Number)
sed �s/gnu/U&/1� text2.txt

13. Find & Replace (Column Number & Specific Line)
  1. sed �1 s/gnu/U&/1� text2.txt
  2. sed �2 s/unix/U&/1� text2.txt
14. Find & Replace (Column Number & g Flag)
sed �1 s/gnu/U&/g1� text2.txt

15. Find & Replace (Duplicate Column)
  1. sed s/(bsd)/1 1 1/g text2.txt
  2. sed s/(gnu)/1 1 1/g text2.txt
16. Find & Replace (Decorate Column)
  1. sed s/(bsd)/[1]/g text2.txt
  2. sed s/(gnu)/{1}/g text2.txt
17. Find & Replace (Delete All Line Numbers)
sed s/^[0-9]*[0-9].//g text3.txt

18. Find & Replace (Case Insensitive)
sed s/bsd/changed/Ig text2.txt

19. Delete Line (Case Insensitive)
  1. sed /unix/Id text5.txt
  2. sed /bsd/Id text5.txt
  3. sed /gnu/Id text5.txt
20. Delete Line (OR Logic Regex)
  1. sed /<-|->/d text4.txt
  2. sed /sign|just/d text4.txt
  3. sed /sign|just|in/d text4.txt

Part 3

 

21. Run Multiple Commands
sed -e s/gnu/U&/g -e s/bsd/U&/g text6.txt

22. Run Multiple Commands (Simpler)
sed s/gnu/U&/g; s/bsd/U&/g text6.txt

23. Combine sed with bash Looping Commands
for i in {6..8}; do sed /bsd/d "text$i.txt"; echo ""; done;

24. Delete Contents of Multiple Files (bash Looping)
for i in {6..8}; do sed -i d text$i.txt; done

25. Rename Multiple Files (bash Looping)
  1. for i in *.txt; do mv "$i" "`echo $i | sed "s/text/flext/g"`"; done
  2. for i in *.txt; do mv -v "$i" "`echo $i | sed "s/^[0-9]*[0-9]//g"`"; done

26. Delete Multiple Files (bash Looping)
  1. for i in *.txt; do rm -v "`echo $i | sed "s/^[0-9]*[0-9]//g"`"; done
  2. for i in *.txt; do rm -v "`echo $i | sed -n "/^[0-9]*[0-9]/p"`"; done

27. Change Slash Delimiters to Another Characters
  1. sed s/unix/CHANGED/g text6.txt
  2. sed s@unix@CHANGED@g text6.txt
  3. sed s!unix!CHANGED!g text6.txt
  4. sed s?unix?CHANGED?g text6.txt

28. Adjust Line Spacing (Single)
sed �G� text6.txt

29. Adjust Line Spacing (Double)
sed G;G text6.txt

30. Find & Replace (Lines Range)
sed 1,3 s/unix/CHANGED/g text6.txt 


Part 4


31. Print Matched Lines
sed -n /unix/p text9.txt

32. Print Reverse-Matched Lines
sed -n /unix/!p text9.txt

33. Bash Looping with Delay Time
for i in *.txt; do sed s/x/[X]/g $i; echo " "; sleep 1; done

34. Print The File Name
sed -n $ F text9.txt

35. Print The First Line
sed �q� text9.txt

36. Print The Last Line
sed -n $ p text9.txt

37. Count Total Line Number
sed -n $ = text9.txt

38. Print Multiple Files First Lines (bash Looping)
  1. for i in *.txt; do sed �q� $i; done
  2. for i in *.txt; do sed -n $ F $i; sed q $i; done
39. Print Multiple Files Last Lines (bash Looping)
  1. for i in *.txt; do sed -n $ p $i; done
  2. for i in *.txt; do sed -n $ F $i; sed -n $ p $i; done
40. Count Multiple Files Line Numbers (bash Looping)
for i in *.txt; do sed -n $ F; $ = "$i"; done


Part 5


41. Delete Comment Lines (Double Slash Style)
sed /^//.*$/d text12.txt

42. Delete Comment Lines (Double Slash Style, Except At Line Beginning)
sed s+([^!]//.*$)++g text12.txt

43. Delete Comment Lines (Hash Style)
sed /^#[^!].*.$/d text13.txt

44. Delete Comment Lines (Slash-Asterisk Style)
sed //*/,/*//d text14.txt

45. Boolean Operator OR
sed -E -n /this|line|return/p text14.txt

46. Boolean Operator AND
  1. sed -n /this.*comment/p text14.txt
  2. sed -n /this.*slash.*comment.*/p text14.txt
47. Multiple Convert Images (PNG to JPEG)
for i in *.png; do convert -verbose "$i" "`echo $i | sed s/.png/.jpeg/g`"; done

48. Multiple Convert Images (JPEG to PNG)
for i in *.jpeg; do convert -verbose "$i" "`echo $i | sed s/.jpeg/.png/g`"; done

49. Insert A Single Line
  1. sed 1i # THIS IS A NEW LINE text13.txt
  2. sed 3i # THIS IS A NEW LINE text13.txt
50. Insert Multiple Lines
sed 3i # THIS IS A NEW LINE # THIS IS ANOTHER LINE text13.txt


Part 6


51. Print Only Lines Between Two Patterns
  1. sed -n /gnu/,/dunix/p text15.txt
  2. sed -n /dunix/,/sunos/Ip text15.txt
52. Delete Only Comment Lines Between Address Range
  1. sed 10,19{//*/,/*//d} text14.txt
  2. sed 10,19{////d} text14.txt
53. Delete Only Comment Lines Between Two Patterns
  1. sed /printf/,/printf/{//*/,/*//d} text14.txt
  2. sed /^/,/main/{//*/,/*//d} text14.txt
54. Edit Only Matched Lines Between Address Range
sed 4,7{s/x/[X]/Ig} text15.txt

55. Edit All Uppercase Characters (POSIX Character Class)
sed s/[[:upper:]]/[X]/g text15.txt

56. Edit All Lowercase Characters (POSIX Character Class)
sed s/[[:lower:]]/[X]/g text15.txt

57. Edit All Punctuation Characters (POSIX Character Class)
sed s/[[:punct:]]/[X]/g text15.txt

58. Edit All Uppercase & Lowercase (POSIX Character Class)
sed s/[[:alpha:]]/[X]/g text15.txt

59. Edit All Numeric Characters (POSIX Character Class)
sed s/[[:digit:]]/[X]/g text15.txt

60. Edit All Space & Tab Characters (POSIX Character Class)
sed s/[[:blank:]]/[X]/g text15.txt

Tuesday, April 25, 2017

Posted by beni in , , , , , , , , , , | April 25, 2017

A Collection of Reviews Tutorials About Desktop Environments in GNU Linux



This article lists all UbuntuBuzz articles in intros, reviews, and tutorials about 10 desktop environments in GNU/Linux. UbuntuBuzz provides both basic usage and customization guides for every of the big four KDE, GNOME, XFCE, and LXDE; plus the similar guides for MATE and Cinnamon; and further UbuntuBuzz also provides intros or reviews for Unity, Manokwari, Budgie, and DDE. If you are looking for GNU/Linux desktop environments related articles, then this list and these all UbuntuBuzz articles are for you.
Subscribe to UbuntuBuzz Telegram Channel https://telegram.me/ubuntubuzz to get article updates directly.

1. KDE
  • Intro: http://www.ubuntubuzz.com/2015/07/beginner-kde-desktop-usage-guide.html
  • Customization: http://www.ubuntubuzz.com/2015/11/beginner-kde-desktop-customization-guide.html
  • Intro KDE Connect: http://www.ubuntubuzz.com/2016/11/introducing-kde-connect-control-your-computer-from-your-phone.html
  • Dolphin Guide: http://www.ubuntubuzz.com/2015/10/how-to-use-kde-file-manager-dolphin.html 
  • Absolute Handy Image Manipulations in Dolphin: http://www.ubuntubuzz.com/2016/05/how-to-convert-resize-rotate-or.html

2. GNOME
  • Intro: http://www.ubuntubuzz.com/2015/06/beginner-gnome-3-desktop-usage-guide.html
  • Customization: http://www.ubuntubuzz.com/2015/08/beginner-gnome-desktop-customization.html
  • Review GNOME 3.22: http://www.ubuntubuzz.com/2016/11/an-introduction-to-gnome-322-for-complete-beginner.html 
  • Intro GNOME Software Center: http://www.ubuntubuzz.com/2016/04/introducing-gnome-software.html

3. XFCE
  • Intro: http://www.ubuntubuzz.com/2015/08/beginner-xfce-desktop-usage-guide.html
  • Customization: http://www.ubuntubuzz.com/2015/11/beginner-xfce-desktop-customization.html

4. LXDE
  • Intro: http://www.ubuntubuzz.com/2015/08/beginner-lxde-desktop-usage-guide.html
  • Customization: http://www.ubuntubuzz.com/2015/11/beginner-lxde-desktop-customization-guide.html

5. Unity
  • Intro: http://www.ubuntubuzz.com/2015/08/beginner-ubuntu-unity-desktop-usage.html

6. Manokwari
  • Intro: http://www.ubuntubuzz.com/2015/08/beginner-blankon-manokwari-desktop.html
  • Review: http://www.ubuntubuzz.com/2016/11/a-preview-into-manokwari-desktop-environment-from-blankon-x-tambora.html


7. MATE
  • Intro: http://www.ubuntubuzz.com/2015/07/beginner-mate-desktop-usage-guide.html
  • Customization: http://www.ubuntubuzz.com/2015/08/beginner-mate-desktop-customization-guide.html
  • Caja Guide: http://www.ubuntubuzz.com/2015/10/how-to-use-mate-file-manager-caja.html

8. Cinnamon
  • Intro: http://www.ubuntubuzz.com/2015/08/beginner-cinnamon-desktop-usage-guide.html
  • Customization: http://www.ubuntubuzz.com/2015/08/beginner-cinnamon-desktop-customization-guide.html

9. Budgie
  • Review: http://www.ubuntubuzz.com/2016/10/desktop-environment-review-budgie.html

10. DDE
  • Review: http://www.ubuntubuzz.com/2016/10/gnulinux-review-deepin-153.html 

Monday, April 3, 2017

Posted by beni in , , , , , , | April 03, 2017

5 GNU AWK Practical Examples Part 1



This is the first part of GNU awk command line examples the series in UbuntuBuzz for complete beginners. I planned to continue my previously GNU sed examples the series here, for GNU awk. In this first article, I provide the simplest and basical things about printing in awk. GNU awk is available built-in in almost every GNU/Linux system, including Ubuntu. I hope this article and the rest of the series help everyone a lot.
Subscribe to UbuntuBuzz Telegram Channel https://telegram.me/ubuntubuzz to get article updates directly.


About GNU awk


awk is a programming language name and also a program name, originated from UNIX system (dated back around 30 years ago), which its name is an abbreviation from Aho-Weinberger-Kernighan (read https://en.wikipedia.org/wiki/AWK). As a computer program, awk works to process and manipulate text, especially to filter and edit it in a simple but advanced way, using its own AWK language. GNU awk is a program compatible completely with AWK language and the UNIX awk program, originated from GNU operating system, by The GNU Project. The official page of GNU awk is https://www.gnu.org/software/gawk.


Text Sample


This is the text used as example in this article.  I saved this text in a file named students.txt. I will demonstrate how to use awk towards this text file.

awk { print } students.txt
NAME    ID      OS      MARK
Parker  01      Darwin  19
Zorro   02      BSD     56
Kent    03      GNU     11
Wayne   04      UNIX    9
Robin   05      Plan9   17
Logan   06      VMS     98


1. Basic Printing


Command:
$ awk { print } students.txt

Output:
master@master:/tmp> awk { print $3," ",$4 } students.txt
OS       MARK
Darwin   19
BSD      56
GNU      11
UNIX     9
Plan9    17
VMS      98
master@master:/tmp> 



2. Print Particular Column


Command:
$ awk { print $1 } students.txt


Output:
master@master:/tmp> awk { print $1 } students.txt
NAME
Parker
Zorro
Kent
Wayne
Robin
Logan
master@master:/tmp>


3. Print More Than One Columns


Command:
$ awk { print $3," ",$4 } students.txt


Output:
master@master:/tmp> awk { print $3," ",$4 } students.txt
OS       MARK
Darwin   19
BSD      56
GNU      11
UNIX     9
Plan9    17
VMS      98
master@master:/tmp>



4. Print Columns Reordered


Command:
$ awk { print $4," ",$3," ",$2," ",$1 }


Output:
master@master:/tmp> awk { print $4," ",$3," ",$2," ",$1 } students.txt
MARK     OS      ID      NAME
19       OS/2    01      Parker
56       BSD     02      Zorro
11       GNU     03      Kent
9        UNIX    04      Wayne
17       Plan9   05      Robin
98       VMS     06      Logan
master@master:/tmp>


5. Print A Line


Command:
$ awk NR==1 students.txt
$ awk NR==4 students.txt


Output:

master@master:/tmp> awk NR==1 students.txt
NAME    ID      OS      MARK
master@master:/tmp> awk NR==4 students.txt
Kent    03      GNU     11
master@master:/tmp>


About GNU awk


awk is a computer language name and also a program name, originated from UNIX system (dated back about 30 years ago), consisted of Aho-Weinberger-Kernighan. As a computer program, awk works to manipulate text, especially to filter and edit it in a simple but advanced way, using its own awk language. The program awk from UNIX is proprietary, but its specification is free, and GNU awk is a program from GNU operating system created by The GNU Project as free software to replace UNIX awk completely. GNU awk contains no UNIX awk source code, because its created from scratch.

Search