diff --git a/awkward.md b/awkward.md index db762aa..d3acf0e 100644 --- a/awkward.md +++ b/awkward.md @@ -7,7 +7,7 @@ These examples explore the combined use of AWK and SED for text processing tasks ### Input File (input.txt) ``` -John Doe,25,Engineer +Carl Sanchez,25,Engineer Jane Smith,30,Designer Bob Johnson,22,Developer ``` @@ -29,7 +29,7 @@ Name Age Job\ ``` Name Age Job --------------- --- ---------- -John Doe 25 Engineer +Carl Sanchez 25 Engineer Jane Smith 30 Designer Bob Johnson 22 Developer ``` @@ -47,20 +47,18 @@ date ### Goal -Print lines containing "a" or "e" using AWK and SED. +Print lines containing "c" or "r" using AWK and SED. ### Solution ```bash -awk '/a|e/' input.txt | sed -n '/a\|e/p' +awk '/c|r/' input.txt | sed -n '/c\|r/p' ``` ### Output ``` -apple -banana -date +cherry ``` ## Example 3: AWK and SED for Filtering and Sorting @@ -116,7 +114,7 @@ awk 'BEGIN{RS="\\."} /sed/' input.txt | sed 's/sed/AWK/g' ### Output ``` -Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua +AWK do eiusmod tempor incididunt ut labore et dolore magna aliqua ``` ## Example 5: AWK and SED for HTML Tag Extraction @@ -145,8 +143,10 @@ sed -n 's/<[^>]*>//p' input.html | awk '{print tolower($0)}' ``` div class="container" p +/p a href="https://example.com" /a +/div ``` ## Example 6: AWK and SED for JSON Formatting @@ -155,9 +155,9 @@ a href="https://example.com" ```json { - "name": "John Doe", + "name": "Carl Sanchez", "age": 30, - "city": "New York" + "city": "Indianapolis" } ``` @@ -175,9 +175,9 @@ awk -v RS= '{$1=$1}1' input.json | sed 's/":"/": "/g; s/{/{\n/g; s/}/\n}/g' ``` { - "name": "John Doe", + "name": "Carl Sanchez", "age": 30, - "city": "New York" + "city": "Indianapolis" } ``` @@ -335,9 +335,9 @@ sed -n '/