string manipulation in AWK or in C [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a problem, I have a file with some number delimited by "". For example "125" etc.
An example of the file is:
10.0.0.0 11.0.0.0 "1200"
10.0.0.1 11.0.0.0.1 "200"
11.0.0.1 11.0.0.2 "320"
I use AWK for take the data but my problem is that I have to take only the integer value of the third column without "" because after I need to have some calculation with this numbers.
The solution is good also in C language.
Someone can help me?
Thanks

In awk, you'll have to strip off the quotes manually
$ echo '"2134"' | awk '{gsub(/(^")|("$)/,"",$1); print $1+2}'
2136
Obviously, this is not a C answer.

Related

bash array from string keeping only content between delimiters [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm trying to create a bash script that uses info pulled from Wikipedia via curl to help sort my music collection. I've gotten it to reliably return the information I want, but because of Wikipedia's formatting, there is sometimes information I want to discard. It is also not always formatted consistently; sometimes it is on multiple lines, and sometimes only one, but the information I want is consistently delimited between "[[" and "]]". I want to keep only the text between [[ and ]] and ignore the rest. All of the solutions I've found so far use sed and rely on consistent formatting. Basically what I want to do is take a long string formatted:
{{[[abcd]]efgh[[hijk]]lmno
[[pqrs]]
[[tuvw]]yz}}
and create an array with the values
abcd
hijk
pqrs
tuvw
With GNU grep and a Perl-compatible regular expression (PCRE):
grep -Po '(?<=\[\[).*?(?=]])' file
Output:
abcd
hijk
pqrs
tuvw

How to repeat string using the array of input [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
So a user can input this in the bash script when ask: 1,2,3,4,5,6 comma separated.
Now what I wanted is to append and repeat it with the string so the results would be like:
hi1 hi2 hi3 hi4 hi5 hi6
This works with:
"hi"{1,2,3,4,5,6}
The problem is using the user input to the loop to be used as the parameter to it. I tried using this but it does not work.
"hi"{$USERINPUT}
I do not have deep experience with bash to know this part.
Using bash pattern substitution and printf:
printf "hi%s " ${USERINPUT//,/ }
printf does not require a loop and prints as many strings as there are arguments.
The bash substitution is ${parameter/pattern/string} which is documented in the bash man page.
How about using sed?
$ echo "$USERINPUT" | sed 's/[0-9][0-9]*/hi&/g;s/,/ /g'
hi1 hi2 hi3 hi4 hi5 hi6

Linux script in C get file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have own script in C for linux, it is working with string loaded from file. I compiled on server gcc -pthread -o pipeline pipeline.c. It is working. Now I am running this script any like this ./pipeline UPPERCASE LOWERCASE < my_file.txt. I can read all arguments but I dont know how to read file name behind < in this script. It is possible, or how is it working?
The contents of that file will show up on your process's standard input (stdin). You don't get the name of the file, as the same interface will be used in situations where there's no filename, such as when the output of another process is piped to yours (doSomething | pipeline UPPERCASE LOWERCASE), or when the user's terminal is used for input by default.

Is it possible to pipe multiple inputs into one program? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a C program that takes in 2 separate inputs through the read(0,buffer,size(buffer)) function.
They take two different inputs. Is it possible, through bash command only, to pipe two pytho -c or perl -e scripts into the C program? Or do I have to change its source code? Thanks in advance
You can use a command group
{
echo "First command"
echo "Second command"
} | nl
Or on one line for your interactive editing convenience:
{ echo "First"; echo "Second"; } | nl

Using the man command in Unix, I want to list file names with file size etc. [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
By using the man command I want to list the names of the files I have already created with extra information such as filesize, date of modification etc.
I know I have to use the man command possibly something like:
man ls | documents
But this would not seem to work. If anyone would know how to do this that would be great? Any help would be much appreciated.
You use man to read the contents of the manual, not list files.
Use ls to list your files.
Use ls -l to list files with extra information.
Use ls -la to list all files (including hidden) with extra information.

Resources