Skip to content

ToCode Solution: תרגול awk#150

Open
Yulia88 wants to merge 1 commit intotocodeil:masterfrom
Yulia88:32_awk_lab
Open

ToCode Solution: תרגול awk#150
Yulia88 wants to merge 1 commit intotocodeil:masterfrom
Yulia88:32_awk_lab

Conversation

@Yulia88
Copy link
Copy Markdown

@Yulia88 Yulia88 commented Jun 12, 2017

No description provided.

Copy link
Copy Markdown
Collaborator

@ynonp ynonp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. Still remained ex 4

Answer:


cat /etc/shells |awk 'BEGIN{ORS="n\n"};1'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


Answer:

cat /etc/shells |awk '{sub(/^/, ">")};1'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

3. Write an awk one-liner to swap the first and last words in the output of "help cd"

4. The command /sbin/ifconfig prints information about network interfaces on the machine. A sample output is provided in the file "ifconfig.sample", and looks like this:
help cd |awk '{tmp=$1;$1=$NF;$NF=tmp;print}'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍




I don't have such file, can I use something else similar (can you tell me which?)? No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take the above text and copy it into a file, or run /sbin/ifconfig > config.txt to get the info into a file named config.txt

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ynon

I copied manually, but I don't what was the order in original file, and I don't know which pattern I need to look for, I can't know how the lines start..

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Yulia,

The file consists of blocks, each looks more or less like this:

utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
        inet6 fe80::3270:cbed:df94:e32d%utun0 prefixlen 64 scopeid 0xa
        nd6 options=201<PERFORMNUD,DAD>

The first line in a block starts with a word (an interface name) and all other lines begin with spaces. So for example this awk program counts how many blocks are in the file:

/^[a-z]/ {
  blocks++
}

END {
  print "Input had " blocks " blocks"
}

Take it as a starter and try to proceed from here. We'll solve it together on our next skype talk

Copy link
Copy Markdown
Collaborator

@ynonp ynonp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Work




I don't have such file, can I use something else similar (can you tell me which?)? No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Yulia,

The file consists of blocks, each looks more or less like this:

utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
        inet6 fe80::3270:cbed:df94:e32d%utun0 prefixlen 64 scopeid 0xa
        nd6 options=201<PERFORMNUD,DAD>

The first line in a block starts with a word (an interface name) and all other lines begin with spaces. So for example this awk program counts how many blocks are in the file:

/^[a-z]/ {
  blocks++
}

END {
  print "Input had " blocks " blocks"
}

Take it as a starter and try to proceed from here. We'll solve it together on our next skype talk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants