Questions tagged [ifs]

IFS is a variable in Unix shells (Bourne, POSIX sh, bash, ksh, …) that controls how unescaped substitutions are split into words.

IFS (short for "input field separator" and often referred to as "internal field separator") is a variable in Unix shells (, , , , , , , , …) that controls how strings are split into multiple fields. Most notably, variable substitutions (e.g. $foo) which are not inside double quotes or in a few other protected locations are split into multiple fields based on the value of IFS; the same goes for command substitutions (e.g. $(foo)). Each character that is present in IFS is a field separator. The default value contains a space, a tab and a newline.

For other meanings of the acronym IFS, use the appropriate tag:

  • IBM Integrated file system
  • QNX Image Filesystem
  • ERP by Industrial and Financial Systems AB
293 questions
2
votes
3 answers

Bash convert file to lowercase and sort

I am trying to write a script that will take in an inputFile, convert it to lowercase, sort it, and then store the results back in the original file. I'm fairly new to bash, so this is the solution I've come up with so far: awk '{ print tolower($0)…
raphnguyen
  • 3,565
  • 18
  • 56
  • 74
2
votes
2 answers

Bash while loop with read and IFS

I have to parse a file in the following format: line1_param1:line1_param2:line1_param3: line1_param2:line2_param2:line2_param3: line1_param3:line3_param2:line3_param3: And process it line by line, extracting all parameters from current line.…
Dejwi
  • 4,393
  • 12
  • 45
  • 74
2
votes
2 answers

IFS=$'\n' deleted the "n"

I have problem with "IFS=$'\n'. old_IFS=$IFS file="Good morning Good morning Good morning Good morning Good morning" IFS=$'\n' for line in $file do echo $line done IFS=$old_IFS When I execute the script: Good mor i g Good mor i g Good…
2
votes
3 answers

Associative array from querystring in bash?

How do I get an associative array from a query string in Bash? - Attempt: #!/usr/bin/env bash # Querystring (implementation stolen from http://stackoverflow.com/q/3919755) function populate_querystring_array () { param="$1" …
A T
  • 13,008
  • 21
  • 97
  • 158
2
votes
1 answer

bash: `read` doesn't seem to honor IFS

I was under the impression that setting IFS would change the delimiter that read uses when separating a line of text into fields, but clearly I'm missing something: # OK: 'read' sees 3 items separated by spaces $ (IFS=' '; x="aa bb cc"; echo "'$x'";…
Adam Liss
  • 47,594
  • 12
  • 108
  • 150
2
votes
2 answers

CSV parse with IFS bash : choose ";" as the separator

I have a CSV with 130 cols and i need to do 3 csv with that. I'm looping with a while and IFS because i need to do someting with the vars on each row. Here what i did : while IFS=";" read [my 130 vars] [what i do with the vars] done <…
Neringan
  • 185
  • 1
  • 1
  • 5
2
votes
2 answers

How to escape a variable in Bash when passing to a command-line argument

I've got a Bash script (Cygwin) that uses some Windows paths with spaces in them. Consequently, I have escaped the space with a \ in my variable definition. Everything within the script works fine. However, I need to pass this variable as an…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
2
votes
1 answer

Using the internal field separator with curl

When I do... ls$IFS-l ... I get the output I expect. When I do... curl$IFShttp://www.google.com ... I don't. Am I misunderstanding internal field separators? How could I run a curl command without using any space characters?
Chris
  • 1,501
  • 17
  • 32
1
vote
1 answer

Bash does not remove leading whitespace

I seem to have a very strange problem. I am trying to retrieve JSON field values from a CURL command using jsawk, however jsawk requires its JSON pretty-printed (which can be easily achieved with a properly formatted JSON file thanks to "python…
user1037517
1
vote
1 answer

Identifying repeat tickets in Excel with ifs, index, match, nested if, countifs

I am having fits with an excel formula I just cant figure out and sometimes more than one set of eyes can make short work of a problem. I have been chasing google results for many hours on this, so here I am finally begging for help. One workbook…
1
vote
1 answer

If A ="contact" and B = "" return "XXX" but if A = "contact" and B isn't blank return "Video/Audio"

If A4 ="contact" and B4 = "" return "XXX" but if A4 = "contact" and B4 isn't blank return "Video/Audio" in c4 https://docs.google.com/spreadsheets/d/1OH2i45NyRBThFBMQJ_lYbMtpmYAAzOm0FRp5a1DBOm4/edit?usp=sharing
Stuart
  • 315
  • 1
  • 8
1
vote
1 answer

Shell script - can't create list separating by newline

my code: #!/usr/bin/bash IFS=$'\n'; read -r -a item < "animals.txt" declare -p item animals.txt: dog cat duck bird desired output: declare -a item=([0]="dog" [1]=" cat" [2]=" duck" [3]=" bird") what I get: declare -a…
1
vote
1 answer

how to function this ifs

I need help. Been finding the correct function but I don't really know how to explain in words what I'm finding, not sure if its the right function too but if A1 is 300 or less, B1 will be an amount equals to A1, so C1 will be A1-B1 if A1 is…
Dark3m0z
  • 13
  • 4
1
vote
1 answer

Getting #ERROR! Message when combining valid formulas

I am trying to setup a formula in one line that will calculate the proper date that a contract can be cancelled based on the Texas Addendum for Property Subject to Mandatory Owner's Association. Depending on 3 possible selections, Section A1,…
1
vote
0 answers

Google Sheets - Issue with IFS statement using OR & AND returning TRUE/FALSE

This is the formula I am currently using: =IFS(OR($C28="Sergeant First Class",$C28="Master Sergeant",$C28="First Sergeant",$C28="Warrant Officer",$C28="Junior Lieutenant"),AND(COUNTIFS('TRYOUT LOG'!$S:$S,$D28, 'TRYOUT LOG'!$D:$D, "TRUE",'TRYOUT…