Skip to content

how to extract a substring in bash

I have the following string in bash with length > 4 and I want to extract into str2 the 5 first charachter of str. So How to do it with bash? Answer Do use the expression So in this case: See other usages: Taken from: – wooledge.org – How can I use parameter expansion? How can I get substrings?…

hex code implementation for spawning a shell

I am trying to implement the codes given in smashing the stack for fun and profit by Aleph to learn the basics of buffer overflow attacks. Machine architecture: Ubuntu 12.10 64 bit programs compiled using -m32 flag in gcc So far, I have managed to spawn a shell using the assembly instructions. The next step i…

C — using chdir() function

I’m trying to use chdir() function but can’t work it out. I’m reading from user and find out if he is using “cd”. I always get an error. What am I doing wrong? Code: Answer If the line being entered is something like: then the directory starts at offset 3, not 2. In addition, fge…

Cutting the column including size

I want to cut the column which include the size of files . I use ls -l to view info about files in current localization . I save info about file in txt file ls -l > info.txt , and now I want to cut the column including size . I do cat info.txt | cut -d” -f6 but i

Grouping common elements using awk

The following table illustrates a brief snapshot of the data that I wish to manipulate. I am looking for an awk script that will group similar elements into one group. For eg. if you look at the table below: Numbers (1,2,3,4,6) should all belong to one group. So row1 row2 row4 row8 will be group “1&#822…